diff --git a/src/main/java/com/numberone/backend/domain/token/service/TokenService.java b/src/main/java/com/numberone/backend/domain/token/service/TokenService.java index 52658fe6..9b96da67 100644 --- a/src/main/java/com/numberone/backend/domain/token/service/TokenService.java +++ b/src/main/java/com/numberone/backend/domain/token/service/TokenService.java @@ -19,6 +19,8 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; +import java.util.Optional; + @Service @RequiredArgsConstructor @Transactional(readOnly = true) @@ -42,8 +44,9 @@ public GetTokenResponse loginKakao(GetTokenRequest tokenRequest) { try { ResponseEntity response = restTemplate.exchange(kakaoProperties.getUser_api_url(), HttpMethod.GET, new HttpEntity<>(null, headers), KakaoInfoResponse.class); String email = response.getBody().getKakao_account().getEmail(); - String realname = response.getBody().getKakao_account().getProfile().getNickname(); - return getTokenResponse(email, realname); + String realName = Optional.ofNullable(response.getBody().getKakao_account().getProfile().getNickname()) + .orElse("사용자"); + return getTokenResponse(email, realName); } catch (Exception e) { throw new BadRequestSocialTokenException(); } @@ -57,9 +60,11 @@ public GetTokenResponse loginNaver(GetTokenRequest tokenRequest) { try { ResponseEntity response = restTemplate.exchange(naverProperties.getUser_api_url(), HttpMethod.GET, new HttpEntity<>(null, headers), NaverInfoResponse.class); + String email = response.getBody().getResponse().getEmail(); - String realname = response.getBody().getResponse().getName(); - return getTokenResponse(email, realname); + String realName = Optional.ofNullable(response.getBody().getResponse().getName()) + .orElse("사용자"); + return getTokenResponse(email, realName); } catch (Exception e) { throw new BadRequestSocialTokenException(); }