Skip to content

Commit

Permalink
refactor: 멤버의 로그아웃 로직 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
YongsHub committed Oct 29, 2023
1 parent 51d04f3 commit 9831cbd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ public void socialLoginRedirect(@PathVariable(name = "oauthName") String oauthNa
}

@DeleteMapping("/logout")
public EnvelopeResponse<Void> logout(
@CookieValue(value = "accessToken", defaultValue = "") String accessToken,
@CookieValue(value = "refreshToken", defaultValue = "") String refreshToken,
HttpServletResponse response) {
authService.deleteTokens(accessToken, refreshToken);
public EnvelopeResponse<Void> logout(HttpServletResponse response) {
cookieProvider.setResponseWithCookies(response, null, null);
return EnvelopeResponse.<Void>builder()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletResponse;
import java.time.Clock;
import java.time.LocalDateTime;
import java.util.Objects;

@Service
@Slf4j
Expand Down Expand Up @@ -73,26 +70,6 @@ public CreateMemberTokensResDto createToken(AuthenticatedMember authenticatedMem
.build();
}

@Transactional
public void deleteTokens(String accessToken, String refreshToken) {
Long memberId = null;

try {
if (StringUtils.hasText(accessToken)) {
AuthenticatedMember authenticatedMember = jwtTokenProvider.getParsedClaimsByAccessToken(accessToken);
memberId = authenticatedMember.getMemberId();
} else if (StringUtils.hasText(refreshToken)) {
memberId = jwtTokenProvider.getMemberIdByRefreshToken(refreshToken);
}

if (Objects.nonNull(memberId)) {
memberTokenRepository.deleteById(memberId);
}
} catch (AuthException e) {
log.debug("유효하지 않은 토큰입니다.");
}
}

@Transactional(readOnly = true)
public MemberToken getMemberTokenByRefreshToken(String refreshToken) {
Long memberId = jwtTokenProvider.getMemberIdByRefreshToken(refreshToken);
Expand Down

0 comments on commit 9831cbd

Please sign in to comment.