Compare commits
1 Commits
main
...
adding-pub
| Author | SHA1 | Date | |
|---|---|---|---|
| 0101056b5f |
@@ -1,6 +1,7 @@
|
|||||||
import { ExecutionContext, Injectable } from '@nestjs/common';
|
import { ExecutionContext, Injectable } from '@nestjs/common';
|
||||||
import { AuthGuard as PassportAuthGuard } from '@nestjs/passport';
|
import { AuthGuard as PassportAuthGuard } from '@nestjs/passport';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
import { IS_PUBLIC_KEY } from '../decorators/public.decorator';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthGuard extends PassportAuthGuard('oidc') {
|
export class AuthGuard extends PassportAuthGuard('oidc') {
|
||||||
@@ -9,6 +10,13 @@ export class AuthGuard extends PassportAuthGuard('oidc') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
|
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
|
||||||
|
const isPublic = this.reflector.get<boolean>(
|
||||||
|
IS_PUBLIC_KEY,
|
||||||
|
context.getHandler()
|
||||||
|
)
|
||||||
|
|
||||||
|
if (isPublic) return true;
|
||||||
|
|
||||||
return super.canActivate(context);
|
return super.canActivate(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
4
libs/modules/src/decorators/public.decorator.ts
Normal file
4
libs/modules/src/decorators/public.decorator.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { SetMetadata } from "@nestjs/common";
|
||||||
|
|
||||||
|
export const IS_PUBLIC_KEY = "isPublic";
|
||||||
|
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);
|
||||||
@@ -8,6 +8,10 @@ export * from './auth/public.decorator';
|
|||||||
|
|
||||||
export * from './util/customError';
|
export * from './util/customError';
|
||||||
|
|
||||||
|
// Decorators
|
||||||
|
|
||||||
|
export { IS_PUBLIC_KEY, Public } from './decorators/public.decorator'
|
||||||
|
|
||||||
// User
|
// User
|
||||||
|
|
||||||
export * from './user/user.module';
|
export * from './user/user.module';
|
||||||
|
|||||||
Reference in New Issue
Block a user