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