import { Injectable , CanActivate , ExecutionContext } from '@nestjs/common' ; import { GqlExecutionContext } from '@nestjs/graphql' ; import { Reflector } from '@nestjs/core' ; import UserService from './service/user.service' ; @ Injectable ( ) export class AuthorizationGaurd implements CanActivate { constructor ( private userService , private reflector ) { } public async canActivate ( context ) { const ctx = GqlExecutionContext . create ( context ) . getContext ( ) ; const permissionsRequired = this . reflector . get < string [ ] > ( 'permissions' , context . getHandler ( ) ) ; const userId = ctx . user . id ; const verified = await this . userService . verifyUserPermissions ( userId , permissionsRequired ) ; return verified ; } }