diff --git a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java index 064e367e..2445007c 100644 --- a/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java +++ b/src/main/java/org/sopt/app/application/auth/PlaygroundAuthService.java @@ -1,5 +1,6 @@ package org.sopt.app.application.auth; +import io.jsonwebtoken.ExpiredJwtException; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -80,6 +81,8 @@ private PlaygroundAuthInfo.PlaygroundMain getPlaygroundMember(String accessToken PlaygroundAuthInfo.PlaygroundMain.class ); return response.getBody(); + } catch (ExpiredJwtException e) { + throw new UnauthorizedException(ErrorCode.INVALID_PLAYGROUND_TOKEN.getMessage()); } catch (Exception e) { throw new BadRequestException(ErrorCode.PLAYGROUND_USER_NOT_EXISTS.getMessage()); } @@ -105,7 +108,9 @@ public PlaygroundAuthInfo.RefreshedToken refreshPlaygroundToken(AppAuthRequest.A return response.getBody(); } catch (BadRequest badRequest) { throw new UnauthorizedException(ErrorCode.INVALID_PLAYGROUND_TOKEN.getMessage()); - } + } catch (ExpiredJwtException e) { + throw new UnauthorizedException(ErrorCode.INVALID_PLAYGROUND_TOKEN.getMessage()); + } } public PlaygroundAuthInfo.MainView getPlaygroundUserForMainView(String accessToken) { @@ -146,6 +151,8 @@ private PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(String a return response.getBody(); } catch (BadRequest e) { throw new BadRequestException(ErrorCode.PLAYGROUND_PROFILE_NOT_EXISTS.getMessage()); + } catch (ExpiredJwtException e) { + throw new UnauthorizedException(ErrorCode.INVALID_PLAYGROUND_TOKEN.getMessage()); } } diff --git a/src/main/java/org/sopt/app/application/user/UserService.java b/src/main/java/org/sopt/app/application/user/UserService.java index 79818e09..387500cd 100644 --- a/src/main/java/org/sopt/app/application/user/UserService.java +++ b/src/main/java/org/sopt/app/application/user/UserService.java @@ -69,4 +69,17 @@ public AppAuthRequest.AccessTokenRequest getPlaygroundToken(UserInfo.Id userId) return token; } + @Transactional + public void updatePlaygroundToken(UserInfo.Id userId, String playgroundToken) { + val user = userRepository.findUserById(userId.getId()) + .orElseThrow(() -> new UnauthorizedException(ErrorCode.INVALID_REFRESH_TOKEN.getMessage())); + val newUser = User.builder() + .id(user.getId()) + .username(user.getUsername()) + .playgroundId(user.getPlaygroundId()) + .playgroundToken(playgroundToken) + .build(); + userRepository.save(newUser); + } + } diff --git a/src/main/java/org/sopt/app/facade/AuthFacade.java b/src/main/java/org/sopt/app/facade/AuthFacade.java index 81f02a51..f27d397a 100644 --- a/src/main/java/org/sopt/app/facade/AuthFacade.java +++ b/src/main/java/org/sopt/app/facade/AuthFacade.java @@ -54,6 +54,7 @@ public Token getRefreshToken(RefreshRequest refreshRequest) { val existingToken = userService.getPlaygroundToken(userId); val playgroundToken = playgroundAuthService.refreshPlaygroundToken(existingToken); val playgroundMember = playgroundAuthService.getPlaygroundInfo(playgroundToken.getAccessToken()); + userService.updatePlaygroundToken(userId, playgroundToken.getAccessToken()); val appToken = jwtTokenService.issueNewTokens(userId, playgroundMember); return authResponseMapper.of(appToken.getAccessToken(), appToken.getRefreshToken(),