Skip to content

Commit

Permalink
comment:주석 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
youcastle03 committed Nov 1, 2024
1 parent 2bc1460 commit 48a8446
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public class KakaoAuthController {
private final KakaoProperties kakaoProperties;
private final KakaoService kakaoService;

/**
* 카카오 로그인페이지로 리다이렉션
* @param response
* @throws IOException
*/
@GetMapping("/login")
public void redirectKakaoLogin(HttpServletResponse response) throws IOException {
String url = kakaoProperties.authUrl() +
Expand All @@ -37,13 +42,24 @@ public void redirectKakaoLogin(HttpServletResponse response) throws IOException
response.sendRedirect(url);
}

/**
* 카카오 로그인후 jwt토큰 발급
* @param code
* @return
*/
@GetMapping("/callback")
public ResponseEntity<TokenResponseDto> getAccessToken(@RequestParam String code){
KakaoTokenResponsed token = kakaoService.getKakaoTokenResponse(code);
String jwt = kakaoService.login(token.accessToken(), token.refreshToken());
return ResponseEntity.ok(new TokenResponseDto(jwt));
}

/**
* 카카오 로그아웃후 카카오계정과 함께 로그아웃으로 리다이렉션
* @param response
* @param userid
* @throws IOException
*/
@PostMapping("/logout")
public void logout(HttpServletResponse response, @LoginUser Long userid) throws IOException{
String url = kakaoProperties.logoutUrl() +
Expand All @@ -52,7 +68,10 @@ public void logout(HttpServletResponse response, @LoginUser Long userid) throws
response.sendRedirect(url);
}


/**
* 카카오계정과 함께 로그아웃
* @return 카카오계정과 함꼐 로그아웃 페이지
*/
@GetMapping("/logoutWithKakao/callback")
public ResponseEntity<?> logoutWithKakao(){
return ResponseEntity.ok().build();
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/jeje/work/aeatbe/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public class UserService {
private final KakaoService kakaoService;



/**
* 카카오 id로 유저 id(pk)를 반환
* @param kakaoId
* @return Long 유저의 id
*/
public Long getUserId(String kakaoId){
Optional<User> user = userRepository.findByKakaoId(kakaoId);
if(user.isPresent()){
Expand All @@ -37,11 +41,21 @@ public Long getUserId(String kakaoId){
return null;
}

/**
* 주어진 jwt토큰을 검증하여 이미 있는 유저인지 확인한다.
* @param token
* @return boolean 이미 존재하는 유저인지
*/
public boolean validateToken(String token) {
String kakaoId = jwtUtil.getKakaoId(token);
return userRepository.findByKakaoId(kakaoId).isPresent();
}

/**
* 유저 정보를 반환한다,
* @param userId
* @return UserInfoResponseDto
*/
public UserInfoResponseDto getUserInfo(Long userId){
User user = userRepository.findById(userId)
.orElseThrow(()-> new UserNotFoundException("잘못된 유저입니다."));
Expand Down

0 comments on commit 48a8446

Please sign in to comment.