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.
20 lines
681 B
20 lines
681 B
import {Middleware} from '../../http/routing/Middleware'
|
|
import {Inject, Injectable} from '../../di'
|
|
import {SecurityContext} from '../SecurityContext'
|
|
import {ResponseObject} from '../../http/routing/Route'
|
|
import {error} from '../../http/response/ErrorResponseFactory'
|
|
import {NotAuthorizedError} from '../NotAuthorizedError'
|
|
import {HTTPStatus} from '../../util'
|
|
|
|
@Injectable()
|
|
export class AuthRequiredMiddleware extends Middleware {
|
|
@Inject()
|
|
protected readonly security!: SecurityContext
|
|
|
|
async apply(): Promise<ResponseObject> {
|
|
if ( !this.security.hasUser() ) {
|
|
return error(new NotAuthorizedError(), HTTPStatus.FORBIDDEN)
|
|
}
|
|
}
|
|
}
|