Last active
June 15, 2020 07:06
-
-
Save ralcorta/8c79fa75f30bff2a2e6585c8e699fc64 to your computer and use it in GitHub Desktop.
Medium post: NesjJs Public endpoit with Global Auth - 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common'; | |
import { JwtAuthGuard } from './jwt-auth.guard'; | |
import { Reflector } from '@nestjs/core'; | |
import { Observable } from 'rxjs'; | |
@Injectable() | |
export class AuthGuard extends JwtAuthGuard implements CanActivate { | |
public constructor(private readonly reflector: Reflector) { super() } | |
public canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> { | |
const isPublic = this.reflector.get<boolean>("isPublic", context.getHandler()); | |
if (isPublic) { | |
return true; | |
} | |
return super.canActivate(context); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment