Auth: always populate req.models.user, thus reducing db requests
This commit is contained in:
parent
28349b791e
commit
fae5c68cd0
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wms-core",
|
||||
"version": "0.21.2",
|
||||
"version": "0.21.3",
|
||||
"description": "Node web application framework and toolbelt.",
|
||||
"repository": "https://gitlab.com/ArisuOngaku/wms-core",
|
||||
"author": "Alice Gaudon <alice@gaudon.pro>",
|
||||
|
@ -15,7 +15,7 @@ export default class AuthComponent extends ApplicationComponent<void> {
|
||||
public async init(router: Router): Promise<void> {
|
||||
router.use(async (req, res, next) => {
|
||||
req.authGuard = this.authGuard;
|
||||
res.locals.user = await (await req.authGuard.getProof(req))?.getResource();
|
||||
req.models.user = res.locals.user = await (await req.authGuard.getProof(req))?.getResource();
|
||||
next();
|
||||
});
|
||||
}
|
||||
@ -31,7 +31,6 @@ export const REQUIRE_REQUEST_AUTH_MIDDLEWARE = async (req: Request, res: Respons
|
||||
return;
|
||||
}
|
||||
|
||||
req.models.user = await proof.getResource();
|
||||
next();
|
||||
};
|
||||
|
||||
@ -39,7 +38,6 @@ export const REQUIRE_AUTH_MIDDLEWARE = async (req: Request, res: Response, next:
|
||||
// Via request
|
||||
let proof = await req.authGuard.isAuthenticatedViaRequest(req);
|
||||
if (proof) {
|
||||
req.models.user = await proof.getResource();
|
||||
next();
|
||||
return;
|
||||
}
|
||||
@ -54,7 +52,6 @@ export const REQUIRE_AUTH_MIDDLEWARE = async (req: Request, res: Response, next:
|
||||
return;
|
||||
}
|
||||
|
||||
req.models.user = await proof.getResource();
|
||||
next();
|
||||
};
|
||||
export const REQUIRE_GUEST_MIDDLEWARE = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
|
||||
|
Loading…
Reference in New Issue
Block a user