Skip to content

Commit

Permalink
fix: 로그인시 refreshtoken 재발급하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
choihuk committed Feb 2, 2025
1 parent b275c40 commit 832b651
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import tipitapi.drawmytoday.common.exception.BusinessException;
import tipitapi.drawmytoday.common.exception.ErrorCode;
Expand Down Expand Up @@ -68,9 +69,11 @@ public ResponseJwtToken login(HttpServletRequest request, RequestAppleLogin requ
user = userService.registerUser(
appleIdToken.getEmail(), SocialCode.APPLE, oAuthAccessToken.getRefreshToken());
} else {
Auth auth = authRepository.findByUser(user)
.orElseThrow(() -> new BusinessException(ErrorCode.INTERNAL_SERVER_ERROR));
auth.setRefreshToken(oAuthAccessToken.getRefreshToken());
if (StringUtils.hasText(oAuthAccessToken.getRefreshToken())) {
Auth auth = authRepository.findByUser(user)
.orElseThrow(() -> new BusinessException(ErrorCode.INTERNAL_SERVER_ERROR));
auth.setRefreshToken(oAuthAccessToken.getRefreshToken());
}
}

String jwtAccessToken = jwtTokenProvider.createAccessToken(user.getUserId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import tipitapi.drawmytoday.common.exception.BusinessException;
import tipitapi.drawmytoday.common.exception.ErrorCode;
Expand Down Expand Up @@ -60,9 +61,11 @@ public ResponseJwtToken login(HttpServletRequest request) {
user = userService.registerUser(
oAuthUserProfile.getEmail(), SocialCode.GOOGLE, accessToken.getRefreshToken());
} else {
Auth auth = authRepository.findByUser(user)
.orElseThrow(() -> new BusinessException(ErrorCode.INTERNAL_SERVER_ERROR));
auth.setRefreshToken(accessToken.getRefreshToken());
if (StringUtils.hasText(accessToken.getRefreshToken())) {
Auth auth = authRepository.findByUser(user)
.orElseThrow(() -> new BusinessException(ErrorCode.INTERNAL_SERVER_ERROR));
auth.setRefreshToken(accessToken.getRefreshToken());
}
}

String jwtAccessToken = jwtTokenProvider.createAccessToken(user.getUserId(),
Expand Down

0 comments on commit 832b651

Please sign in to comment.