You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
870 B
27 lines
870 B
import {HTTPKernelModule} from "../HTTPKernelModule";
|
|
import {Injectable, Inject} from "@extollo/di";
|
|
import {uuid_v4} from "@extollo/util";
|
|
import {HTTPKernel} from "../HTTPKernel";
|
|
import {Request} from "../../lifecycle/Request";
|
|
import {Logging} from "../../../service/Logging";
|
|
|
|
@Injectable()
|
|
export class SetSessionCookieHTTPModule extends HTTPKernelModule {
|
|
@Inject()
|
|
protected readonly logging!: Logging
|
|
|
|
public static register(kernel: HTTPKernel) {
|
|
kernel.register(this).first()
|
|
}
|
|
|
|
public async apply(request: Request) {
|
|
if ( !request.cookies.has('extollo.session') ) {
|
|
const session = `${uuid_v4()}-${uuid_v4()}`
|
|
|
|
this.logging.verbose(`Starting session: ${session}`)
|
|
request.cookies.set('extollo.session', session) // FIXME allow configuring this
|
|
}
|
|
return request
|
|
}
|
|
}
|