Route - prevent pre/post middleware from being applied twice
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:
parent
7506d6567d
commit
faa8a31102
@ -7,6 +7,7 @@ import {SessionSecurityContext} from '../contexts/SessionSecurityContext'
|
|||||||
import {SecurityContext} from '../SecurityContext'
|
import {SecurityContext} from '../SecurityContext'
|
||||||
import {ORMUserRepository} from '../orm/ORMUserRepository'
|
import {ORMUserRepository} from '../orm/ORMUserRepository'
|
||||||
import {AuthConfig, AuthenticatableRepositories} from '../config'
|
import {AuthConfig, AuthenticatableRepositories} from '../config'
|
||||||
|
import {Logging} from '../../service/Logging'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Injects a SessionSecurityContext into the request and attempts to
|
* Injects a SessionSecurityContext into the request and attempts to
|
||||||
@ -17,7 +18,11 @@ export class SessionAuthMiddleware extends Middleware {
|
|||||||
@Inject()
|
@Inject()
|
||||||
protected readonly config!: Config
|
protected readonly config!: Config
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
protected readonly logging!: Logging
|
||||||
|
|
||||||
async apply(): Promise<ResponseObject> {
|
async apply(): Promise<ResponseObject> {
|
||||||
|
this.logging.debug('Applying session auth middleware...')
|
||||||
const context = <SessionSecurityContext> this.make(SessionSecurityContext, this.getRepository())
|
const context = <SessionSecurityContext> this.make(SessionSecurityContext, this.getRepository())
|
||||||
this.request.registerSingletonInstance(SecurityContext, context)
|
this.request.registerSingletonInstance(SecurityContext, context)
|
||||||
await context.resume()
|
await context.resume()
|
||||||
|
@ -87,11 +87,15 @@ export class Route extends AppClass {
|
|||||||
for ( const group of stack ) {
|
for ( const group of stack ) {
|
||||||
route.prepend(group.prefix)
|
route.prepend(group.prefix)
|
||||||
group.getGroupMiddlewareDefinitions()
|
group.getGroupMiddlewareDefinitions()
|
||||||
.each(def => route.prependMiddleware(def))
|
.where('stage', '=', 'pre')
|
||||||
|
.each(def => {
|
||||||
|
route.prependMiddleware(def)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( const group of this.compiledGroupStack ) {
|
for ( const group of this.compiledGroupStack ) {
|
||||||
group.getGroupMiddlewareDefinitions()
|
group.getGroupMiddlewareDefinitions()
|
||||||
|
.where('stage', '=', 'post')
|
||||||
.each(def => route.appendMiddleware(def))
|
.each(def => route.appendMiddleware(def))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user