mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
33 lines
783 B
TypeScript
33 lines
783 B
TypeScript
import {
|
|
ExecutionContext,
|
|
Injectable,
|
|
Scope,
|
|
SetMetadata,
|
|
} from '@nestjs/common';
|
|
import { Reflector } from '@nestjs/core';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
import { ClsService } from 'nestjs-cls';
|
|
|
|
export const IS_PUBLIC_KEY = 'isPublic';
|
|
export const PublicRoute = () => SetMetadata(IS_PUBLIC_KEY, true);
|
|
|
|
@Injectable()
|
|
export class JwtAuthGuard extends AuthGuard('jwt') {
|
|
constructor(
|
|
private reflector: Reflector,
|
|
private readonly cls: ClsService,
|
|
) {
|
|
super();
|
|
}
|
|
canActivate(context: ExecutionContext) {
|
|
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
|
context.getHandler(),
|
|
context.getClass(),
|
|
]);
|
|
if (isPublic) {
|
|
return true;
|
|
}
|
|
return super.canActivate(context);
|
|
}
|
|
}
|