issue #39
All checks were successful
Test CI / build (push) Successful in 1m29s

- Access 토큰 만료 시 Refresh 토큰으로 Access 토큰 갱신 로직 구현 중
This commit is contained in:
2025-12-01 22:36:01 +09:00
parent 56cee12c81
commit 58d092536e
6 changed files with 96 additions and 11 deletions

View File

@@ -1,5 +1,45 @@
import { Injectable } from "@nestjs/common";
import { ExecutionContext, Injectable, UnauthorizedException } from "@nestjs/common";
import { Reflector } from "@nestjs/core";
import { TokenExpiredError } from "@nestjs/jwt";
import { AuthGuard } from "@nestjs/passport";
import { IS_PUBLIC_KEY } from "src/common/decorators/public.decorator";
@Injectable()
export class JwtRefreshAuthGuard extends AuthGuard('refresh-token') {}
export class JwtRefreshAuthGuard extends AuthGuard('refresh-token') {
constructor(private reflector: Reflector) {
super();
}
canActivate(context: ExecutionContext) {
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
context.getHandler(),
context.getClass()
]);
if (isPublic) {
return true;
}
return super.canActivate(context);
}
handleRequest(err: any, user:any, info:any) {
if (info instanceof TokenExpiredError) {
throw new UnauthorizedException({
statusCode: 401,
message: 'Refresh Token Expired',
code: 'RefreshTokenExpired'
});
}
if (err || !user) {
throw new UnauthorizedException({
statusCode: 401,
message: 'Invalid Token',
code: 'InvalidToken'
});
}
return user;
}
}