Add AuthComponent.getAuthGuard()

This commit is contained in:
Alice Gaudon 2020-09-23 08:46:37 +02:00
parent 75c2b72f57
commit 2effaf13eb

View File

@ -4,10 +4,10 @@ import AuthGuard from "./AuthGuard";
import Controller from "../Controller"; import Controller from "../Controller";
import {ForbiddenHttpError} from "../HttpError"; import {ForbiddenHttpError} from "../HttpError";
export default class AuthComponent extends ApplicationComponent<void> { export default class AuthComponent<T extends AuthGuard<any>> extends ApplicationComponent<void> {
private readonly authGuard: AuthGuard<any>; private readonly authGuard: T;
public constructor(authGuard: AuthGuard<any>) { public constructor(authGuard: T) {
super(); super();
this.authGuard = authGuard; this.authGuard = authGuard;
} }
@ -19,6 +19,10 @@ export default class AuthComponent extends ApplicationComponent<void> {
next(); next();
}); });
} }
public getAuthGuard(): T {
return this.authGuard;
}
} }
export const REQUIRE_REQUEST_AUTH_MIDDLEWARE = async (req: Request, res: Response, next: NextFunction): Promise<void> => { export const REQUIRE_REQUEST_AUTH_MIDDLEWARE = async (req: Request, res: Response, next: NextFunction): Promise<void> => {