diff --git a/src/main/java/com/depromeet/domain/auth/application/AuthService.java b/src/main/java/com/depromeet/domain/auth/application/AuthService.java index 0e54083f3..6af856d49 100644 --- a/src/main/java/com/depromeet/domain/auth/application/AuthService.java +++ b/src/main/java/com/depromeet/domain/auth/application/AuthService.java @@ -103,7 +103,7 @@ public SocialLoginResponse socialLoginMember(IdTokenRequest request, OauthProvid private Member fetchOrCreate(OidcUser oidcUser) { return memberRepository - .findByOauthInfo(extractOauthInfo(oidcUser)) + .findByOauthInfoAndStatus(extractOauthInfo(oidcUser), MemberStatus.NORMAL) .orElseGet(() -> saveMember(oidcUser)); } diff --git a/src/main/java/com/depromeet/domain/member/api/MemberController.java b/src/main/java/com/depromeet/domain/member/api/MemberController.java index 20e7078a6..15dace813 100644 --- a/src/main/java/com/depromeet/domain/member/api/MemberController.java +++ b/src/main/java/com/depromeet/domain/member/api/MemberController.java @@ -8,6 +8,7 @@ import com.depromeet.domain.member.dto.response.MemberFindOneResponse; import com.depromeet.domain.member.dto.response.MemberSearchResponse; import com.depromeet.domain.member.dto.response.MemberSocialInfoResponse; +import com.depromeet.global.util.CookieUtil; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; @@ -23,6 +24,7 @@ public class MemberController { private final MemberService memberService; + private final CookieUtil cookieUtil; @Operation(summary = "회원 정보 확인", description = "로그인 된 회원의 정보를 확인합니다.") @GetMapping("/me") @@ -62,9 +64,9 @@ public List memberNicknameSearch( // TODO: 테스트 코드 작성 필요 @Operation(summary = "회원 탈퇴", description = "회원탈퇴를 진행합니다.") @DeleteMapping("/withdrawal") - public ResponseEntity memberWithdrawal(@Valid @RequestBody UsernameCheckRequest request) { - memberService.withdrawal(request); - return ResponseEntity.ok().build(); + public ResponseEntity memberWithdrawal() { + memberService.withdrawal(); + return ResponseEntity.ok().headers(cookieUtil.deleteTokenCookies()).build(); } @Operation(summary = "소셜 로그인 정보 조회하기", description = "소셜 로그인 정보를 조회합니다.") diff --git a/src/main/java/com/depromeet/domain/member/application/MemberService.java b/src/main/java/com/depromeet/domain/member/application/MemberService.java index f98eaedce..1baca346a 100644 --- a/src/main/java/com/depromeet/domain/member/application/MemberService.java +++ b/src/main/java/com/depromeet/domain/member/application/MemberService.java @@ -135,12 +135,8 @@ public List searchMemberNickname(String nickname) { return response; } - public void withdrawal(UsernameCheckRequest request) { - final Member member = - memberRepository - .findByUsername(request.username()) - .orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND)); - + public void withdrawal() { + final Member member = memberUtil.getCurrentMember(); refreshTokenRepository.deleteById(member.getId()); member.withdrawal(); } diff --git a/src/main/java/com/depromeet/domain/member/dao/MemberRepository.java b/src/main/java/com/depromeet/domain/member/dao/MemberRepository.java index df936de37..186f9304e 100644 --- a/src/main/java/com/depromeet/domain/member/dao/MemberRepository.java +++ b/src/main/java/com/depromeet/domain/member/dao/MemberRepository.java @@ -1,6 +1,7 @@ package com.depromeet.domain.member.dao; import com.depromeet.domain.member.domain.Member; +import com.depromeet.domain.member.domain.MemberStatus; import com.depromeet.domain.member.domain.OauthInfo; import io.lettuce.core.dynamic.annotation.Param; import java.util.List; @@ -10,7 +11,7 @@ public interface MemberRepository extends JpaRepository { - Optional findByOauthInfo(OauthInfo oauthInfo); + Optional findByOauthInfoAndStatus(OauthInfo oauthInfo, MemberStatus status); boolean existsByUsername(String username); diff --git a/src/main/java/com/depromeet/global/util/CookieUtil.java b/src/main/java/com/depromeet/global/util/CookieUtil.java index e859f4630..399adc157 100644 --- a/src/main/java/com/depromeet/global/util/CookieUtil.java +++ b/src/main/java/com/depromeet/global/util/CookieUtil.java @@ -48,4 +48,33 @@ private String determineSameSitePolicy() { } return Cookie.SameSite.NONE.attributeValue(); } + + public HttpHeaders deleteTokenCookies() { + + String sameSite = determineSameSitePolicy(); + + ResponseCookie accessTokenCookie = + ResponseCookie.from(ACCESS_TOKEN_COOKIE_NAME, "") + .path("/") + .maxAge(0) + .secure(true) + .sameSite(sameSite) + .httpOnly(false) + .build(); + + ResponseCookie refreshTokenCookie = + ResponseCookie.from(REFRESH_TOKEN_COOKIE_NAME, "") + .path("/") + .maxAge(0) + .secure(true) + .sameSite(sameSite) + .httpOnly(false) + .build(); + + HttpHeaders headers = new HttpHeaders(); + headers.add(HttpHeaders.SET_COOKIE, accessTokenCookie.toString()); + headers.add(HttpHeaders.SET_COOKIE, refreshTokenCookie.toString()); + + return headers; + } }