29 lines
817 B
TypeScript
29 lines
817 B
TypeScript
|
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'
|
||
|
|
||
|
@Injectable()
|
||
|
export default class SetSessionCookie extends Module {
|
||
|
|
||
|
public static register(kernel: Kernel) {
|
||
|
kernel.register(this).after(PrepareRequest)
|
||
|
}
|
||
|
|
||
|
constructor(
|
||
|
protected utility: Utility,
|
||
|
) {
|
||
|
super()
|
||
|
}
|
||
|
|
||
|
public async apply(request: Request): Promise<Request> {
|
||
|
if ( !(await request.cookies.has('daton.session')) ) {
|
||
|
await request.cookies.set('daton.session', `${this.utility.uuid()}-${this.utility.uuid()}`)
|
||
|
}
|
||
|
return request
|
||
|
}
|
||
|
|
||
|
}
|