Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
gunom committed Oct 28, 2023
2 parents d3b0e16 + e099508 commit c115788
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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());
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/sopt/app/application/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
1 change: 1 addition & 0 deletions src/main/java/org/sopt/app/facade/AuthFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit c115788

Please sign in to comment.