Skip to content

Commit

Permalink
[fix] #10 토큰 발급 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ziiyouth committed Dec 30, 2023
1 parent ffe5ceb commit f55185d
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,23 @@ public EmailResponseDto sendMail(EmailPostRequestDto emailPostRequestDto) {

public MemberSignUpResponseDto signUp(MemberSignUpRequestDto memberSignUpRequestDto) {
Long newMemberId = createMember(memberSignUpRequestDto);
String accessToken = issueNewToken(newMemberId);
String refreshToken = issueNewToken(newMemberId);
String accessToken = issueNewAccessToken(newMemberId);
String refreshToken = issueNewRefreshToken(newMemberId);
return MemberSignUpResponseDto.of(newMemberId, memberSignUpRequestDto.name(), accessToken, refreshToken);
}

public MemberSignInResponseDto signIn(MemberSignInRequestDto memberSignInRequestDto) {
User user = getUserFromEmail(memberSignInRequestDto.email());
if (!authenticatePassword(memberSignInRequestDto.password(), user.getPassword())) {
validatePassword(memberSignInRequestDto.password(), user.getPassword());
String accessToken = issueNewAccessToken(user.getId());
String refreshToken = issueNewRefreshToken(user.getId());
return MemberSignInResponseDto.of(user.getId(), accessToken, refreshToken);
}

private void validatePassword(String enteredPassword, String storedPassword) {
if (!authenticatePassword(enteredPassword, storedPassword)) {
throw new UnauthorizedException(INVALID_PASSWORD);
}
String accessToken = issueNewToken(user.getId());
String refreshToken = issueNewToken(user.getId());
return MemberSignInResponseDto.of(user.getId(), accessToken, refreshToken);
}

private void checkDuplicateEmail(String email) {
Expand All @@ -61,10 +65,14 @@ private void checkDuplicateEmail(String email) {
}
}

private String issueNewToken(Long memberId) {
private String issueNewAccessToken(Long memberId) {
return jwtProvider.getIssueToken(memberId, true);
}

private String issueNewRefreshToken(Long memberId) {
return jwtProvider.getIssueToken(memberId, false);
}

private Long createMember(MemberSignUpRequestDto memberSignUpRequestDto) {
User newUser = User.createUser(
memberSignUpRequestDto.email(),
Expand Down

0 comments on commit f55185d

Please sign in to comment.