Skip to content

Commit 3683c97

Browse files
authored
refactor(be): add userId in refresh token response (#195)
refactor: add userId in refresh token response
1 parent 7767c4b commit 3683c97

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

apps/server/src/auth/auth.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export class AuthController {
3737
async token(@Req() request: Request) {
3838
const refreshToken = request.cookies[this.REFRESH_TOKEN];
3939
const accessToken = await this.authService.generateAccessToken(refreshToken);
40-
return { accessToken };
40+
const userId = this.authService.getInfo(refreshToken);
41+
return { accessToken, userId };
4142
}
4243

4344
@Post('logout')

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export class AuthService implements OnModuleInit {
2727
private readonly usersRepository: UsersRepository,
2828
) {}
2929

30+
getInfo(refreshToken: string) {
31+
const user = this.refreshTokens[refreshToken];
32+
return user ? user.userId : null;
33+
}
34+
3035
getRefreshTokenExpireTime() {
3136
return this.REFRESH_TOKEN_CONFIG.EXPIRE_INTERVAL;
3237
}
@@ -82,7 +87,6 @@ export class AuthService implements OnModuleInit {
8287
const tokenData = this.refreshTokens[refreshToken];
8388
if (!tokenData) throw RefreshTokenException.invalid();
8489

85-
//FE측 cookie 만료 시간과 서버 측 만료 시간 간의 오차 대비
8690
if (tokenData.expiredAt < new Date()) {
8791
this.removeRefreshToken(refreshToken);
8892
throw RefreshTokenException.expired();

apps/server/src/auth/swagger/login.swagger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const TokenRefreshSwagger = () =>
6565
schema: {
6666
example: {
6767
accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
68+
userId: 3,
6869
},
6970
},
7071
}),

0 commit comments

Comments
 (0)