Skip to content

Commit

Permalink
[FIX] 회원탈퇴 시 토큰으로 회원 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
hcg0127 committed Aug 10, 2024
1 parent 5e006ec commit d6e7a3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/main/java/umc/haruchi/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,18 @@ public void newLogout(String accessToken) {
// }

// 새 회원 탈퇴 - 이유 저장 + 회원 정보 영구 삭제
public void newWithdrawer(String reason, Member member) {
public void newWithdrawer(String reason, String accessToken) {
Withdrawer withdrawer = Withdrawer.builder()
.reason(reason)
.build();
withdrawerRepository.save(withdrawer);

if (memberRepository.findByEmail(member.getEmail()).isPresent()) {
memberRepository.delete(member);
}
else {
throw new MemberHandler(ErrorStatus.NO_MEMBER_EXIST);
}
String email = jwtUtil.getEmail(accessToken);

Member member = memberRepository.findByEmail(email)
.orElseThrow(() -> new MemberHandler(ErrorStatus.NO_MEMBER_EXIST));

memberRepository.delete(member);
}

// 기존 회원 탈퇴 - 이유 저장 (보안 강화 시 주석 처리 해제)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ public ApiResponse<MemberResponseDTO> logout(@RequestHeader("Authorization") Str
@PostMapping("/delete")
@Operation(summary = "회원탈퇴 API", description = "회원탈퇴를 진행하는 API (토큰 만료 및 회원 영구 삭제)")
public ApiResponse<MemberResponseDTO> deleteMember(@RequestHeader("Authorization") String accessToken,
@RequestParam String reason,
@AuthenticationPrincipal Member member) {
@RequestParam String reason) {
memberService.newWithdrawer(reason,accessToken.substring(7));
memberService.newLogout(accessToken.substring(7));
memberService.newWithdrawer(reason,member);
return ApiResponse.onSuccess(null);
}

Expand Down

0 comments on commit d6e7a3e

Please sign in to comment.