feat: add jwt auth guard and profile endpoint
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { IS_PUBLIC_KEY } from '../constants';
|
||||
import { JwtAuthGuard } from './jwt-auth.guard';
|
||||
import { ExecutionContext, Injectable } from '@nestjs/common';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@Injectable()
|
||||
export class GlobalAuthGuard extends JwtAuthGuard {
|
||||
constructor(
|
||||
/**
|
||||
* Inject Reflector
|
||||
*/
|
||||
private readonly reflector: Reflector,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
canActivate(
|
||||
context: ExecutionContext,
|
||||
): boolean | Promise<boolean> | Observable<boolean> {
|
||||
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
||||
context.getHandler(),
|
||||
context.getClass(),
|
||||
]);
|
||||
|
||||
if (isPublic) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.canActivate(context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
@Injectable()
|
||||
export class JwtAuthGuard extends AuthGuard('jwt') {}
|
||||
Reference in New Issue
Block a user