19 lines
689 B
TypeScript
Executable File
19 lines
689 B
TypeScript
Executable File
import { ExecutionContext, Injectable, UnauthorizedException } from "@nestjs/common";
|
|
import { AuthGuard } from "@nestjs/passport";
|
|
import { Observable } from "rxjs";
|
|
|
|
import { JWT_STRATEGY_NAME } from "../../../common/constants";
|
|
import { AuthMessage } from "../../../common/enums/message.enum";
|
|
|
|
@Injectable()
|
|
export class JwtAuthGuard extends AuthGuard(JWT_STRATEGY_NAME) {
|
|
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
|
|
return super.canActivate(context);
|
|
}
|
|
|
|
handleRequest(err: unknown, user: any, _info: unknown) {
|
|
if (err || !user) throw new UnauthorizedException(AuthMessage.TOKEN_EXPIRED_OR_INVALID);
|
|
return user;
|
|
}
|
|
}
|