Skip to content

Commit

Permalink
Merge pull request #222 from boostcampwm2023/refactor/220-login-api-r…
Browse files Browse the repository at this point in the history
…efactor

[Refactor] 로그인 API 응답 수정 및 리팩토링
  • Loading branch information
JoonSoo-Kim authored Dec 6, 2023
2 parents 2b32536 + 793ad6b commit b093b88
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 0 additions & 3 deletions BE/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import { NaverOAuthStrategy } from "./strategies/naver.strategy";
PassportModule.register({ defaultStrategy: "jwt" }),
JwtModule.register({
secret: process.env.JWT_SECRET,
signOptions: {
expiresIn: process.env.JWT_ACCESS_TOKEN_TIME,
},
}),
],
controllers: [AuthController],
Expand Down
14 changes: 9 additions & 5 deletions BE/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class AuthService {
throw new NotFoundException("올바르지 않은 비밀번호입니다.");
}

return this.createUserTokens(userId, request.ip);
return this.createUserTokens(userId, user.nickname, request.ip);
}

async signOut(user: User): Promise<void> {
Expand All @@ -53,7 +53,10 @@ export class AuthService {
const expiredResult = JSON.parse(payload.toString());

const userId = expiredResult.userId;
return this.createUserTokens(userId, request.ip);

const userNickname = (await User.findOne({ where: { userId: userId } }))
.nickname;
return this.createUserTokens(userId, userNickname, request.ip);
}

async naverSignIn(user: User, request: Request): Promise<AccessTokenDto> {
Expand All @@ -64,7 +67,7 @@ export class AuthService {
await user.save();
}

return this.createUserTokens(userId, request.ip);
return this.createUserTokens(userId, user.nickname, request.ip);
}

async kakaoSignIn(user: User, request: Request): Promise<AccessTokenDto> {
Expand All @@ -75,11 +78,12 @@ export class AuthService {
await user.save();
}

return this.createUserTokens(userId, request.ip);
return this.createUserTokens(userId, user.nickname, request.ip);
}

private async createUserTokens(
userId: string,
nickname: string,
requestIp: string,
): Promise<AccessTokenDto> {
const accessTokenPayload = { userId };
Expand All @@ -98,6 +102,6 @@ export class AuthService {
// 86000s = 24h
await this.redisClient.set(userId, refreshToken, "EX", 86400);

return new AccessTokenDto(accessToken);
return new AccessTokenDto(accessToken, nickname);
}
}
4 changes: 3 additions & 1 deletion BE/src/auth/dto/auth-access-token.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export class AccessTokenDto {
accessToken: string;
nickname: string;

constructor(accessToken: string) {
constructor(accessToken: string, nickname: string) {
this.accessToken = accessToken;
this.nickname = nickname;
}
}

0 comments on commit b093b88

Please sign in to comment.