diff --git a/src/main/java/com/goormthon3/team49/domain/user/application/UserLoginService.java b/src/main/java/com/goormthon3/team49/domain/user/application/UserLoginService.java index f3f2186..945c5e4 100644 --- a/src/main/java/com/goormthon3/team49/domain/user/application/UserLoginService.java +++ b/src/main/java/com/goormthon3/team49/domain/user/application/UserLoginService.java @@ -105,4 +105,11 @@ public User saveOrUpdateUser(UserInfoResponseDto userInfo) { return userRepository.save(user); } + public Long getKakaoUserIdFromAccessToken(String accessToken) { + + UserInfoResponseDto userInfo = getUserInfo(accessToken); + Long kakaoUserId = userInfo.getId(); + + return kakaoUserId; + } } diff --git a/src/main/java/com/goormthon3/team49/domain/user/presentation/UserLoginController.java b/src/main/java/com/goormthon3/team49/domain/user/presentation/UserLoginController.java index ec91f7c..7b85a4c 100644 --- a/src/main/java/com/goormthon3/team49/domain/user/presentation/UserLoginController.java +++ b/src/main/java/com/goormthon3/team49/domain/user/presentation/UserLoginController.java @@ -78,4 +78,18 @@ public ResponseEntity saveUserInfo(@RequestHeader("Authorization") String aut return ResponseEntity.ok(response); } + + @GetMapping("/kakao-user-id") + public ResponseEntity getKakaoUserId(@RequestHeader("Authorization") String authorization) { + + if (authorization == null || !authorization.startsWith("Bearer ")) { + return new ResponseEntity<>("Missing or invalid Authorization header", HttpStatus.UNAUTHORIZED); + } + + String accessToken = authorization.substring(7); + Long kakaoUserId = userLoginService.getKakaoUserIdFromAccessToken(accessToken); + + return ResponseEntity.ok(Map.of("kakao_user_id", kakaoUserId)); + } + }