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
16 lines
461 B
TypeScript
16 lines
461 B
TypeScript
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
import { GqlExecutionContext } from '@nestjs/graphql';
|
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
export class WorkspaceAuthGuard implements CanActivate {
|
|
canActivate(
|
|
context: ExecutionContext,
|
|
): boolean | Promise<boolean> | Observable<boolean> {
|
|
const ctx = GqlExecutionContext.create(context);
|
|
const request = ctx.getContext().req;
|
|
|
|
return request.workspace !== undefined;
|
|
}
|
|
}
|