Skip to content

Commit

Permalink
Merge pull request #78 from Central-MakeUs/feature/testUser
Browse files Browse the repository at this point in the history
[Feature] 토큰 재발급 api 추가
  • Loading branch information
dainnida authored Feb 8, 2025
2 parents f5ac3ee + 6320a40 commit fceabaf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public SuccessResponse<?> deleteTestUser(@RequestParam String email) {
return SuccessResponse.ok(new HashMap<>());
}

@PostMapping("/refresh/accessToken")
@Operation(summary = "테스트 계정 토큰 재발급", description = "개발 환경에서 사용할 테스트 계정의 새로운 access 토큰을 발급합니다.")
public SuccessResponse<User> refreshTestToken(@RequestBody UserTestRequest request) {
return SuccessResponse.ok(userService.refreshTestToken(request));
}

@GetMapping()
public SuccessResponse<List<User>> getAllUsers() {

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/cmc/mercury/domain/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ public void deleteTestUser(String email) {
userRepository.delete(user);
}

@Transactional
public User refreshTestToken(UserTestRequest request) {

// 해당 이메일의 TEST 계정 찾기
User user = userRepository.findByEmailAndOauthType(request.email(), OAuthType.TEST)
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));

// 토큰 재발급
long tokenValidity = request.isShortLivedAccessToken()
? 20000 // 20초
: accessTokenValidity;

String accessToken = jwtProvider.createToken(user.getId(), user.getEmail(), "AccessToken", tokenValidity);
response.setHeader("Authorization", "Bearer " + accessToken);

return user;
}

public List<User> getListUsers() {
return userRepository.findAll();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spring:

jpa:
hibernate:
ddl-auto: create
ddl-auto: update
properties:
hibernate:
format_sql: true
Expand Down

0 comments on commit fceabaf

Please sign in to comment.