Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ public CommonResponse<LogoutRes> logout(@CookieValue(value = "refreshToken", req
@Operation(summary = "회원탈퇴", description = "isDeleted값을 true로 바꾸고 관련 정보를 삭제합니다.")
public CommonResponse<WithdrawRes> withdraw(
@Parameter(description = "사용자정보", required = true)
@AuthenticationPrincipal Long userId
@AuthenticationPrincipal Long userId,
HttpServletResponse response
){
return CommonResponse.success(authService.withdraw(userId));
return CommonResponse.success(authService.withdraw(userId, response));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public User login(String code, HttpServletResponse response) {
User user = userRepository.findByProviderId(kakaoId)
.orElseGet(() -> userRepository.save(User.createTmpUser(kakaoId, nickname)));

if(user.getIsDeleted()) {
user.reactivate();
}

String accessToken = jwtProvider.createAccessToken(user);
String refreshToken = jwtProvider.createRefreshToken(user);
LocalDateTime expiryTime = jwtProvider.getRefreshTokenExpiry(refreshToken);
Expand Down Expand Up @@ -120,14 +124,14 @@ public void logout(String refreshToken, HttpServletResponse response){
}

@Transactional
public WithdrawRes withdraw(Long userId) {
public WithdrawRes withdraw(Long userId, HttpServletResponse response) {
User user = findUser(userId);

if(user.getIsDeleted()){
throw new GlobalException(UserErrorCode.USER_ALREADY_DELETED);
}

user.updateIsDeleted();
user.updateIsDeletedAndRole();

tokenRepository.deleteByUser(user);
pinRepository.deleteByUser(user);
Expand All @@ -137,6 +141,9 @@ public WithdrawRes withdraw(Long userId) {
feedbackRepository.deleteByUser(user);
bookmarkRepository.deleteByUser(user);

jwtProvider.deleteRefreshTokenCookie(response);
jwtProvider.deleteAuthCheckCookie(response);

return new WithdrawRes();
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/ureca/uble/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,10 @@ public void updateUserInfo(Rank rank, Gender gender, LocalDate birthDate, String
}
}

public void updateIsDeleted() { this.isDeleted = true; }
public void updateIsDeletedAndRole() {
this.isDeleted = true;
this.role = Role.TMP_USER;
}

public void reactivate() { this.isDeleted = false; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ void withdrawSuccess(){
when(userRepository.findById(userId)).thenReturn(Optional.of(user));

//when
WithdrawRes res = authService.withdraw(userId);
WithdrawRes res = authService.withdraw(userId, response);

//then
verify(user).updateIsDeleted();
verify(user).updateIsDeletedAndRole();
verify(tokenRepository).deleteByUser(user);
verify(pinRepository).deleteByUser(user);
verify(userCategoryRepository).deleteByUser(user);
Expand All @@ -191,7 +191,7 @@ void withdrawFail(){
when(userRepository.findById(userId)).thenReturn(Optional.empty());

//when, then
assertThrows(GlobalException.class, () -> authService.withdraw(userId));
assertThrows(GlobalException.class, () -> authService.withdraw(userId, response));
verify(tokenRepository, never()).deleteByUser(any());
}
}
Loading