Skip to content

Commit

Permalink
refactor: 사용자 인증 요구사항 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
Choi-JJunho committed Jan 10, 2024
1 parent 2d778a7 commit 52499bc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ public ResponseEntity<Void> logout(@UserAuth User user) {

@PostMapping("/user/refresh")
public ResponseEntity<UserTokenRefreshResponse> refresh(
@UserAuth User user,
@RequestBody @Valid UserTokenRefreshRequest request
) {
UserTokenRefreshResponse tokenGroupResponse = userService.refresh(user, request);
UserTokenRefreshResponse tokenGroupResponse = userService.refresh(request);
return ResponseEntity.ok().body(tokenGroupResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ public interface UserTokenRepository extends Repository<UserToken, Long> {

Optional<UserToken> findById(Long userId);

Optional<UserToken> findByRefreshToken(String refreshToken);

void deleteById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ public void logout(User user) {
userTokenRepository.deleteById(user.getId());
}

public UserTokenRefreshResponse refresh(User user, UserTokenRefreshRequest request) {
UserToken userToken = userTokenRepository.findById(user.getId())
public UserTokenRefreshResponse refresh(UserTokenRefreshRequest request) {
UserToken userToken = userTokenRepository.findByRefreshToken(request.refreshToken())
.orElseThrow(() -> new IllegalArgumentException("refresh token이 존재하지 않습니다. request: " + request));
if (!Objects.equals(userToken.getRefreshToken(), request.refreshToken())) {
throw new IllegalArgumentException("refresh token이 일치하지 않습니다. request: " + request);
}
User user = userRepository.findById(userToken.getId())
.orElseThrow(() -> new UserNotFoundException("사용자를 찾을 수 없습니다. refreshToken: " + userToken));
String accessToken = jwtProvider.createToken(user);
return UserTokenRefreshResponse.of(accessToken, userToken.getRefreshToken());
}
Expand Down

0 comments on commit 52499bc

Please sign in to comment.