You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
704 B
29 lines
704 B
import {
|
|
ExecutionContext,
|
|
Injectable,
|
|
UnauthorizedException,
|
|
} from '@nestjs/common';
|
|
import { AuthGuard as NestAuthGuard } from '@nestjs/passport';
|
|
import { Reflector } from '@nestjs/core';
|
|
|
|
@Injectable()
|
|
export class AuthGuard extends NestAuthGuard('jwt') {
|
|
public constructor(private readonly reflector: Reflector) {
|
|
super();
|
|
}
|
|
|
|
canActivate(context: ExecutionContext) {
|
|
const isPublic = this.reflector.get<boolean>(
|
|
'isPublic',
|
|
context.getHandler(),
|
|
);
|
|
|
|
if (isPublic) {
|
|
return true;
|
|
}
|
|
|
|
// Add your custom authentication logic here
|
|
// for example, call super.logIn(request) to establish a session.
|
|
return super.canActivate(context);
|
|
}
|
|
}
|