Skip to content

Commit 559ef44

Browse files
committed
refactor: /api/user/me JWT 기반
- /api/user/me 엔드포인트에서 userId 파라미터 제거 - @AuthenticationPrincipal 사용하여 로그인된 사용자 정보 조회
1 parent 8629435 commit 559ef44

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/java/Devroup/hidaddy/controller/UserController.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,21 @@ public ResponseEntity<?> changeName(
113113
@GetMapping("/me")
114114
@Operation(
115115
summary = "현재 로그인된 유저 정보 조회",
116-
description = "유저의 이름, 전화번호, 배우자 전화번호, 선택된 아기의 이름을 반환합니다."
116+
description = "로그인된 사용자의 이름, 전화번호, 배우자 전화번호, 선택된 아기의 이름을 반환합니다. "
117+
+ "Authorization 헤더에 유효한 Access Token이 필요합니다."
117118
)
118119
@ApiResponses({
119120
@ApiResponse(responseCode = "200", description = "유저 정보 조회 성공"),
121+
@ApiResponse(responseCode = "401", description = "인증되지 않은 사용자 (로그인 필요)"),
120122
@ApiResponse(responseCode = "404", description = "해당 유저를 찾을 수 없음")
121123
})
122-
public ResponseEntity<UserResponse> getMyInfo(@RequestParam Long userId) {
123-
UserResponse userInfo = userService.getUserInfo(userId);
124+
public ResponseEntity<UserResponse> getMyInfo(@AuthenticationPrincipal UserDetailsImpl userDetails) {
125+
if (userDetails == null) {
126+
return ResponseEntity.status(401).build();
127+
}
128+
129+
UserResponse userInfo = userService.getUserInfo(userDetails.getUser().getId());
124130
return ResponseEntity.ok(userInfo);
125131
}
132+
126133
}

0 commit comments

Comments
 (0)