diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java index 0c2fb09..2b9e006 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/AuthService.java @@ -40,20 +40,15 @@ public BaseResponseDto googleLogin(String accessToken) { User user; boolean early; - Mono userInfoMono = getUserGoogleInfo(accessToken); + Mono userInfoMono = getUserInfo(accessToken, "https://www.googleapis.com/oauth2/v2/userinfo", GoogleUserResponseDto.class); GoogleUserResponseDto userInfo = userInfoMono.block(); Optional userData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); - log.info(String.valueOf(userInfo.getEmail())); - log.info(String.valueOf(userInfo.getPicture())); - log.info(String.valueOf(userInfo.getId())); - if(userData.isEmpty()){ user = User.builder() .userNumber(String.valueOf(userInfo.getId())) .roles("USER") - .profileImage(userInfo.getPicture()) .early(true) .build(); @@ -86,15 +81,9 @@ public BaseResponseDto kakaoLogin(String accessToken) { User user; boolean early; - Mono userInfoMono = getUserKakaoInfo(accessToken); + Mono userInfoMono = getUserInfo(accessToken, "https://kapi.kakao.com/v2/user/me", KakaoUserResponseDto.class); KakaoUserResponseDto userInfo = userInfoMono.block(); - - log.info(String.valueOf(userInfo.getKakao_account().getEmail())); - log.info(String.valueOf(userInfo.getKakao_account().getProfile().getProfile_image_url())); - log.info(String.valueOf(userInfo.getKakao_account().getProfile().getNickname())); - - Optional userData = userRepository.findByUserNumber(String.valueOf(userInfo.getId())); @@ -102,7 +91,6 @@ public BaseResponseDto kakaoLogin(String accessToken) { user = User.builder() .userNumber(String.valueOf(userInfo.getId())) .roles("USER") - .profileImage(userInfo.getKakao_account().getProfile().getProfile_image_url()) .early(true) .build(); @@ -131,21 +119,13 @@ public BaseResponseDto kakaoLogin(String accessToken) { return baseResponseDto; } - public Mono getUserKakaoInfo(String accessToken) { + public Mono getUserInfo(String accessToken, String apiUrl, Class responseType) { return webClient .get() - .uri("https://kapi.kakao.com/v2/user/me") // 카카오 사용자 정보 엔드포인트 + .uri(apiUrl) .headers(headers -> headers.setBearerAuth(accessToken)) .retrieve() - .bodyToMono(KakaoUserResponseDto.class); + .bodyToMono(responseType); } - public Mono getUserGoogleInfo(String accessToken) { - return webClient - .get() - .uri("https://www.googleapis.com/oauth2/v2/userinfo") // 카카오 사용자 정보 엔드포인트 - .headers(headers -> headers.setBearerAuth(accessToken)) - .retrieve() - .bodyToMono(GoogleUserResponseDto.class); - } } \ No newline at end of file