Skip to content

Commit

Permalink
✅ Test[#10]: 카카오 로그인 테스트용
Browse files Browse the repository at this point in the history
  • Loading branch information
kduoh99 committed Nov 22, 2024
1 parent 8b1a9f1 commit a05670d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,17 @@ private String[] getKakaoUserInfo(String kakaoAccessToken) throws JsonProcessing

return new String[] {providerId, profileImageUrl};
}

@Transactional
public SocialLoginResponse kakaoLoginWithAccessToken(String kakaoAccessToken) {
try {
String[] userInfo = getKakaoUserInfo(kakaoAccessToken);

return userRepository.findByProviderAndProviderId(Provider.KAKAO, userInfo[0])
.map(this::handleExistingUserLogin)
.orElseGet(() -> SocialLoginResponse.of(userInfo[0], userInfo[1]));
} catch (JsonProcessingException e) {
throw new KakaoAuthException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ public class UserController {
private final AppleLoginService appleLoginService;
private final TokenRenewService tokenRenewService;

@PostMapping("/kakao/accessToken")
@Operation(
summary = "카카오 로그인",
description = "카카오 액세스 토큰을 사용하여 로그인 또는 회원가입 필요 여부를 판별합니다. DB에 사용자 정보가 있으면 로그인 성공, 없으면 회원가입 필요 상태를 반환합니다.",
security = {},
responses = {
@ApiResponse(responseCode = "200", description = "로그인 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청"),
@ApiResponse(responseCode = "401", description = "인증되지 않은 요청"),
@ApiResponse(responseCode = "418", description = "회원가입 필요"),
@ApiResponse(responseCode = "500", description = "서버 오류")
}
)
public ResTemplate<SocialLoginResponse> kakaoLoginWithAccessToken(@RequestBody KakaoLoginRequest request) {
SocialLoginResponse data = kakaoLoginService.kakaoLoginWithAccessToken(request.kakaoCode());
if (data.userId() == null) {
return new ResTemplate<>(HttpStatus.I_AM_A_TEAPOT, "회원가입 필요", data);
}
return new ResTemplate<>(HttpStatus.OK, "로그인 성공", data);
}

@PostMapping("/kakao")
@Operation(
summary = "카카오 로그인",
Expand Down Expand Up @@ -167,7 +188,7 @@ public ResTemplate<RegisterUserResponse> getUserInfoToRegister(@RequestBody Regi
)
public ResTemplate<Void> checkPassword(@RequestBody PwdRequest request, Principal principal) {
userService.checkPassword(request, principal);
return new ResTemplate<>(HttpStatus.OK, "비밀번호 일치");
return new ResTemplate<>(HttpStatus.OK, "비밀번호 일치");
}

// 비밀번호 변경
Expand All @@ -187,6 +208,7 @@ public ResTemplate<Void> editPassword(@RequestBody PwdRequest request, Principal
userService.editPassword(request, principal);
return new ResTemplate<>(HttpStatus.OK, "비밀번호 변경완료");
}

// 회원탈퇴
@DeleteMapping("/delete")
@Operation(
Expand All @@ -204,6 +226,5 @@ public ResTemplate<Void> deleteUser(Principal principal) {
return new ResTemplate<>(HttpStatus.OK, "탈퇴완료");
}


// 마이페이지 조회
}

0 comments on commit a05670d

Please sign in to comment.