Skip to content

Commit fa47e66

Browse files
authored
refactor(be): remove unnecessary refresh token check in jwt auth guard (#230)
refactor: remove unnecessary refresh token check in jwt auth guard
1 parent fd78a47 commit fa47e66

File tree

2 files changed

+2
-14
lines changed

2 files changed

+2
-14
lines changed

apps/server/src/auth/auth.service.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ export class AuthService implements OnModuleInit {
9393
}
9494
}
9595

96-
hasValidRefreshToken(userId: number, nickname: string) {
97-
return Object.values(this.refreshTokens).some(
98-
(data) => data.userId === userId && data.nickname === nickname && data.expiredAt > new Date(),
99-
);
100-
}
101-
10296
removeRefreshToken(refreshToken: string) {
10397
delete this.refreshTokens[refreshToken];
10498
}

apps/server/src/auth/jwt-auth.guard.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
22
import { JwtService } from '@nestjs/jwt';
33
import { Request } from 'express';
44

5-
import { AuthService } from './auth.service';
65
import { JwtAuthException } from './exceptions/auth.exception';
76

87
@Injectable()
98
export class JwtAuthGuard implements CanActivate {
10-
constructor(
11-
private readonly jwtService: JwtService,
12-
private readonly authService: AuthService,
13-
) {}
9+
constructor(private readonly jwtService: JwtService) {}
10+
1411
async canActivate(context: ExecutionContext) {
1512
const request = context.switchToHttp().getRequest<Request>();
1613
const token = this.extractToken(request);
@@ -19,9 +16,6 @@ export class JwtAuthGuard implements CanActivate {
1916
try {
2017
const payload = await this.jwtService.verifyAsync(token, { secret: process.env.JWT_ACCESS_SECRET });
2118

22-
const validation = this.authService.hasValidRefreshToken(payload.userId, payload.nickname);
23-
if (!validation) throw JwtAuthException.invalidAccessToken();
24-
2519
request['user'] = payload;
2620
return true;
2721
} catch (error) {

0 commit comments

Comments
 (0)