25 lines
763 B
TypeScript
25 lines
763 B
TypeScript
import { CanActivate } from '@nestjs/common';
|
|
import { ExecutionContext, Injectable } from '@nestjs/common';
|
|
import { Reflector } from '@nestjs/core';
|
|
import { AuthGuard as PassportAuthGuard } from '@nestjs/passport';
|
|
import { Observable } from 'rxjs';
|
|
|
|
@Injectable()
|
|
export class AuthGuard extends PassportAuthGuard('azure-ad') implements CanActivate {
|
|
constructor(private readonly reflector: Reflector) {
|
|
super();
|
|
}
|
|
|
|
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);
|
|
}
|
|
} |