Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 멤버의 로그아웃 로직 리팩토링 #297

Merged
merged 1 commit into from
Oct 29, 2023
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 @@ -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
Loading