Optimize metadata queries (#7013)
In this PR: 1. Refactor guards to avoid duplicated queries: WorkspaceAuthGuard and UserAuthGuard only check for existence of workspace and user in the request without querying the database
This commit is contained in:
committed by
Charles Bochet
parent
cf8b1161cc
commit
523df5398a
@ -14,10 +14,10 @@ export const AuthUser = createParamDecorator(
|
||||
(options: DecoratorOptions | undefined, ctx: ExecutionContext) => {
|
||||
const request = getRequest(ctx);
|
||||
|
||||
if (!options?.allowUndefined && (!request.user || !request.user.user)) {
|
||||
if (!options?.allowUndefined && !request.user) {
|
||||
throw new ForbiddenException("You're not authorized to do this");
|
||||
}
|
||||
|
||||
return request.user ? request.user.user : undefined;
|
||||
return request.user;
|
||||
},
|
||||
);
|
||||
|
||||
@ -6,6 +6,6 @@ export const AuthWorkspace = createParamDecorator(
|
||||
(data: unknown, ctx: ExecutionContext) => {
|
||||
const request = getRequest(ctx);
|
||||
|
||||
return request.user ? request.user.workspace : undefined;
|
||||
return request.workspace;
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user