Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 카카오 로그아웃 API 구현 #70

Merged
merged 5 commits into from
Feb 8, 2024
Merged

feat: 카카오 로그아웃 API 구현 #70

merged 5 commits into from
Feb 8, 2024

Conversation

kdkdhoho
Copy link
Collaborator

@kdkdhoho kdkdhoho commented Feb 6, 2024

Description

  • 카카오 로그아웃 API 구현했습니다.
    로그아웃 요청 시, 액세스 토큰 방식서비스 앱 어드민 키 방식으로 총 2가지 방식이 존재합니다.
    서비스 앱 어드민 키 방식보다 액세스 토큰 방식이 쉽고 편하게 구현이 가능한 대신, 카카오에서 발급한 액세스 토큰을 DB에 저장해야 합니다.
    아직 개발 단계이며 데이터가 많이 쌓이지 않았으므로 users 테이블에 함께 저장하도록 했습니다.

    하지만 추후 따로 관리 할 필요가 있어보이며 해당 방법에 대해서는 고민해봐야겠습니다.

Reference

Relation Issues

@kdkdhoho kdkdhoho added the 기능 label Feb 6, 2024
@kdkdhoho kdkdhoho self-assigned this Feb 6, 2024
@kdkdhoho kdkdhoho requested a review from pparkjs as a code owner February 6, 2024 04:49
@kdkdhoho kdkdhoho linked an issue Feb 6, 2024 that may be closed by this pull request
3 tasks
Copy link
Collaborator

@pparkjs pparkjs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로그아웃 잘 구현 하였습니다!
잘 모르는 부분이기에 질문을 중심으로 코멘트 남겼습니다!

Comment on lines +36 to +40
User user = User.initialCreate(
kakaoMember.id(),
kakaoMember.kakaoAccount().email(),
kakaoTokenResponse.accessToken()
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당부분은 kakao에서 가져온 카카오 유저가 실제 우리 서비스에 가입한 유저가 아니면 회원가입을 시키는 과정인거죠!? 그리고 로그아웃을 위해 accessToken저장을 위해 별도 추가하신거고

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정확합니다!

@PatchMapping("/auth/kakao")
ResponseEntity<Void> logout(@RequestHeader(value = AUTHORIZATION) String accessToken) {
authService.logout(accessToken);
return ResponseEntity.noContent().build();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분은 프론트단이 accessToken가지고 해당 uri로 요청하는 거죠?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞습니다!

Comment on lines +51 to +55
public void logout(String accessToken) {
Long userId = jwtManager.read(accessToken);
User user = userRepository.getById(userId);
kakaoOauthClient.logout(user.getKakaoAccessToken());
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 카카오에서 발급한 AccessToken을 테이블에 저장한 이유가 여기있었군요

@@ -28,18 +24,17 @@ public class UserService {

@Transactional(readOnly = true)
public UserInfoResponse getUserInfo(Long userId, String accessToken) {
Optional<User> found = userRepository.findById(userId);
User foundUser = found.orElseThrow(() -> new CustomException(NOT_FOUND));
User user = userRepository.getById(userId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findById를 안하고 getById 하신 이유가 있나요!?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

service 단의 코드 간소화를 위해 했습니다.

@kdkdhoho kdkdhoho merged commit cbce572 into dev Feb 8, 2024
1 check passed
@kdkdhoho kdkdhoho deleted the feat/69 branch February 8, 2024 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

카카오 로그아웃 API 구현
2 participants