Add middleware and logic for bootstrapping the session auth
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import {Inject, Injectable} from '../di'
|
||||
import {Inject, Injectable, Instantiable, StaticClass} from '../di'
|
||||
import {Unit} from '../lifecycle/Unit'
|
||||
import {Logging} from '../service/Logging'
|
||||
import {CanonicalResolver} from '../service/Canonical'
|
||||
import {Middleware} from '../http/routing/Middleware'
|
||||
import {SessionAuthMiddleware} from './middleware/SessionAuthMiddleware'
|
||||
import {AuthRequiredMiddleware} from './middleware/AuthRequiredMiddleware'
|
||||
import {GuestRequiredMiddleware} from './middleware/GuestRequiredMiddleware'
|
||||
import {Middlewares} from '../service/Middlewares'
|
||||
|
||||
/**
|
||||
* Unit class that bootstraps the authentication framework.
|
||||
@@ -10,7 +16,21 @@ export class Authentication extends Unit {
|
||||
@Inject()
|
||||
protected readonly logging!: Logging
|
||||
|
||||
@Inject()
|
||||
protected readonly middleware!: Middlewares
|
||||
|
||||
async up(): Promise<void> {
|
||||
this.container()
|
||||
this.middleware.registerNamespace('@auth', this.getMiddlewareResolver())
|
||||
}
|
||||
|
||||
protected getMiddlewareResolver(): CanonicalResolver<StaticClass<Middleware, Instantiable<Middleware>>> {
|
||||
return (key: string) => {
|
||||
return ({
|
||||
web: SessionAuthMiddleware,
|
||||
required: AuthRequiredMiddleware,
|
||||
guest: GuestRequiredMiddleware,
|
||||
})[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user