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

Fix: ResponseJwtDto에 userId 추가 (#152) #153

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading