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.

37 lines
1.2 KiB

import {HTTPKernelModule} from '../HTTPKernelModule'
import {Injectable} from '../../../di'
import {ErrorWithContext} from '../../../util'
import {HTTPKernel} from '../HTTPKernel'
import {Request} from '../../lifecycle/Request'
import {SetSessionCookieHTTPModule} from './SetSessionCookieHTTPModule'
import {SessionFactory} from '../../session/SessionFactory'
import {Session} from '../../session/Session'
* HTTP kernel middleware that creates the session using the configured driver
* and loads its data using the request's session cookie.
export class InjectSessionHTTPModule extends HTTPKernelModule {
public readonly executeWithBlockingWriteback = true
public static register(kernel: HTTPKernel): void {
public async apply(request: Request): Promise<Request> {
const session = <Session> request.make(Session)
const id = request.cookies.get('extollo.session')
if ( !id ) {
throw new ErrorWithContext('Session ID has not been set. Cannot inject session!')
await session.load()
return request