Skip to content

Commit

Permalink
[fix] 회원가입 프로필 안가져오기 중복 함수 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryeolee committed Nov 11, 2023
1 parent 65b0f3f commit 811a21c
Showing 1 changed file with 5 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,15 @@ public BaseResponseDto googleLogin(String accessToken) {
User user;
boolean early;

Mono<GoogleUserResponseDto> userInfoMono = getUserGoogleInfo(accessToken);
Mono<GoogleUserResponseDto> userInfoMono = getUserInfo(accessToken, "https://www.googleapis.com/oauth2/v2/userinfo", GoogleUserResponseDto.class);
GoogleUserResponseDto userInfo = userInfoMono.block();

Optional<User> 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();

Expand Down Expand Up @@ -86,23 +81,16 @@ public BaseResponseDto kakaoLogin(String accessToken) {

User user;
boolean early;
Mono<KakaoUserResponseDto> userInfoMono = getUserKakaoInfo(accessToken);
Mono<KakaoUserResponseDto> 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<User> userData = userRepository.findByUserNumber(String.valueOf(userInfo.getId()));


if(userData.isEmpty()){
user = User.builder()
.userNumber(String.valueOf(userInfo.getId()))
.roles("USER")
.profileImage(userInfo.getKakao_account().getProfile().getProfile_image_url())
.early(true)
.build();

Expand Down Expand Up @@ -131,21 +119,13 @@ public BaseResponseDto kakaoLogin(String accessToken) {
return baseResponseDto;
}

public Mono<KakaoUserResponseDto> getUserKakaoInfo(String accessToken) {
public <T> Mono<T> getUserInfo(String accessToken, String apiUrl, Class<T> 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<GoogleUserResponseDto> getUserGoogleInfo(String accessToken) {
return webClient
.get()
.uri("https://www.googleapis.com/oauth2/v2/userinfo") // 카카오 사용자 정보 엔드포인트
.headers(headers -> headers.setBearerAuth(accessToken))
.retrieve()
.bodyToMono(GoogleUserResponseDto.class);
}
}

0 comments on commit 811a21c

Please sign in to comment.