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.
33 lines
991 B
33 lines
991 B
import Module from '../Module.ts'
|
|
import Kernel from '../Kernel.ts'
|
|
import {Request} from '../../Request.ts'
|
|
import PrepareRequest from './PrepareRequest.ts'
|
|
import Utility from '../../../service/utility/Utility.ts'
|
|
import {Injectable} from '../../../../../di/src/decorator/Injection.ts'
|
|
import {Logging} from '../../../service/logging/Logging.ts'
|
|
|
|
@Injectable()
|
|
export default class SetSessionCookie extends Module {
|
|
|
|
public static register(kernel: Kernel) {
|
|
kernel.register(this).after(PrepareRequest)
|
|
}
|
|
|
|
constructor(
|
|
protected readonly utility: Utility,
|
|
) {
|
|
super()
|
|
}
|
|
|
|
public async apply(request: Request): Promise<Request> {
|
|
if ( !(await request.cookies.has('daton.session')) ) {
|
|
const cookie = `${this.utility.uuid()}-${this.utility.uuid()}`
|
|
|
|
this.make(Logging).verbose(`Starting session: ${cookie}`)
|
|
await request.cookies.set('daton.session', cookie)
|
|
}
|
|
return request
|
|
}
|
|
|
|
}
|