import { CanActivate , ExecutionContext , Injectable } from '@nestjs/common' ; import { GqlExecutionContext } from '@nestjs/graphql' ; import { AuthGuard } from '@nestjs/passport' ; @ Injectable ( ) export class DiscordAuthGuard extends AuthGuard ( 'discord' ) { async canActivate ( context ) { const activate = ( await super . canActivate ( context ) ) as boolean ; const request = context . switchToHttp ( ) . getRequest ( ) ; await super . logIn ( request ) ; return activate ; } } @ Injectable ( ) export class AuthenticatedGuard implements CanActivate { async canActivate ( context ) { const req = context . switchToHttp ( ) . getRequest ( ) ; return req . isAuthenticated ( ) ; } } @ Injectable ( ) export class GraphQLAuthGuard implements CanActivate { canActivate ( context ) { const ctx = GqlExecutionContext . create ( context ) ; return ctx . getContext ( ) . req . user ; } }