Skip to content

Instantly share code, notes, and snippets.

@ralcorta
Last active June 15, 2020 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralcorta/8c79fa75f30bff2a2e6585c8e699fc64 to your computer and use it in GitHub Desktop.
Save ralcorta/8c79fa75f30bff2a2e6585c8e699fc64 to your computer and use it in GitHub Desktop.
Medium post: NesjJs Public endpoit with Global Auth - 1
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