Skip to content

Commit

Permalink
feat: 소셜 로그인 회원탈퇴 기능 구현 (#282)
Browse files Browse the repository at this point in the history
* fix: 탈퇴한 회원이면 재생성하도록 수정

* fix: 닉네임으로 멤버 제거하는 로직 수정

* feat: 쿠키 삭제 로직 구현
  • Loading branch information
uwoobeat authored Feb 7, 2024
1 parent eb65361 commit f1d578c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +24,7 @@
public class MemberController {

private final MemberService memberService;
private final CookieUtil cookieUtil;

@Operation(summary = "회원 정보 확인", description = "로그인 된 회원의 정보를 확인합니다.")
@GetMapping("/me")
Expand Down Expand Up @@ -62,9 +64,9 @@ public List<MemberSearchResponse> memberNicknameSearch(
// TODO: 테스트 코드 작성 필요
@Operation(summary = "회원 탈퇴", description = "회원탈퇴를 진행합니다.")
@DeleteMapping("/withdrawal")
public ResponseEntity<Void> memberWithdrawal(@Valid @RequestBody UsernameCheckRequest request) {
memberService.withdrawal(request);
return ResponseEntity.ok().build();
public ResponseEntity<Void> memberWithdrawal() {
memberService.withdrawal();
return ResponseEntity.ok().headers(cookieUtil.deleteTokenCookies()).build();
}

@Operation(summary = "소셜 로그인 정보 조회하기", description = "소셜 로그인 정보를 조회합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,8 @@ public List<MemberSearchResponse> 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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,7 +11,7 @@

public interface MemberRepository extends JpaRepository<Member, Long> {

Optional<Member> findByOauthInfo(OauthInfo oauthInfo);
Optional<Member> findByOauthInfoAndStatus(OauthInfo oauthInfo, MemberStatus status);

boolean existsByUsername(String username);

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/depromeet/global/util/CookieUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit f1d578c

Please sign in to comment.