Skip to content

Commit

Permalink
✨ Fix: ResponseJwtDto에 userId 추가 (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
win-luck committed Jan 25, 2024
1 parent 5a887a6 commit ad22c1c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public ApiResponse<ResponseJwtDto> authCheck(@RequestHeader String accessToken)
Long userId = kakaoAuthService.isSignedUp(accessToken); // 유저 고유번호 추출

ResponseJwtDto responseJwtDto = (userId == null) ? null : ResponseJwtDto.builder()
.userId(userId)
.accessToken(jwtTokenProvider.createAccessToken(userId.toString()))
.refreshToken(jwtTokenProvider.createRefreshToken(userId.toString()))
.build();
Expand All @@ -45,27 +46,22 @@ public ApiResponse<ResponseJwtDto> saveUser(@Valid @RequestBody JoinUserDto join
Long userId = userService.saveUser(kakaoAuthService.createUserDto(joinUserDto));

ResponseJwtDto responseJwtDto = (userId == null) ? null : ResponseJwtDto.builder()
.userId(userId)
.accessToken(jwtTokenProvider.createAccessToken(userId.toString()))
.refreshToken(jwtTokenProvider.createRefreshToken(userId.toString()))
.build();

return ApiResponse.success(responseJwtDto, ResponseCode.USER_CREATE_SUCCESS.getMessage());
}

// 토큰 검증 (Jwt 토큰을 서버에 전송하여, 서버가 유효한 토큰인지 확인하고 True 혹은 예외 반환)
@Operation(summary = "[토큰 검증] 토큰 검증", description = "클라이언트가 가지고 있던 Jwt 토큰을 서버에 전송하여, 서버가 유효한 토큰인지 확인하고 OK 혹은 예외를 반환합니다.")
@GetMapping("/token")
public ApiResponse<Boolean> tokenCheck(@RequestHeader String accessToken) {
return ApiResponse.success(jwtTokenProvider.validateAccessToken(accessToken), ResponseCode.TOKEN_CHECK_SUCCESS.getMessage());
}

@Operation(summary = "[토큰 재발급] 토큰 재발급", description = "클라이언트가 가지고 있던 Refresh 토큰을 서버에 전송하여, 서버가 유효한 토큰인지 확인하고 OK 혹은 예외를 반환합니다.")
@PostMapping("/reissue")
public ApiResponse<ResponseJwtDto> reissueToken(@RequestHeader String refreshToken) {
Long userId = jwtTokenProvider.getUserPk(refreshToken);
jwtTokenProvider.validateRefreshToken(userId, refreshToken);

ResponseJwtDto responseJwtDto = (userId == null) ? null : ResponseJwtDto.builder()
.userId(userId)
.accessToken(jwtTokenProvider.createAccessToken(userId.toString()))
.refreshToken(jwtTokenProvider.createRefreshToken(userId.toString()))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@AllArgsConstructor
public class ResponseJwtDto {

private Long userId;
private String accessToken;
private String refreshToken;
}

0 comments on commit ad22c1c

Please sign in to comment.