Skip to content

Commit

Permalink
Merge pull request #140 from Team-Motivoo/chore/#139-add_login_response
Browse files Browse the repository at this point in the history
[CHORE] 소셜 로그인 API Response 추가
  • Loading branch information
jun02160 authored Mar 12, 2024
2 parents 8adddcf + e54ce3b commit 6995704
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ public record LoginResponse (
@JsonProperty("access_token")
String accessToken,
@JsonProperty("refresh_token")
String refreshToken
String refreshToken,

@JsonProperty("is_finished_onboarding")
boolean isFinishedOnboarding,
@JsonProperty("is_matched")
boolean isMatched
){

private static final String BEARER_TYPE = "Bearer";
Expand All @@ -26,7 +31,9 @@ public static LoginResponse of(LoginResult result) {
.nickname(result.nickname())
.tokenType(result.tokenType())
.accessToken(result.accessToken())
.refreshToken(result.refreshToken()).build();
.refreshToken(result.refreshToken())
.isFinishedOnboarding(result.isFinishedOnboarding())
.isMatched(result.isMatched()).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ public record LoginResult(
String tokenType,

String accessToken,
String refreshToken
String refreshToken,

Boolean isFinishedOnboarding,
Boolean isMatched
){

private static final String BEARER_TYPE = "Bearer";

public static LoginResult of(User user, String accessToken, String refreshToken) {
public static LoginResult of(User user, String accessToken, String refreshToken, boolean isFinishedOnboarding, boolean isMatched) {
return LoginResult.builder()
.id(user.getSocialId())
.nickname(user.getNickname())
.tokenType(BEARER_TYPE)
.accessToken(accessToken)
.refreshToken(refreshToken).build();
.refreshToken(refreshToken)
.isFinishedOnboarding(isFinishedOnboarding)
.isMatched(isMatched)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public LoginResult login(OauthTokenCommand tokenRequest) {
SocialPlatform socialPlatform = SocialPlatform.of(providerName);
String refreshToken = jwtTokenProvider.createRefreshToken();


if (socialPlatform.equals(KAKAO)) {
ClientRegistration provider = inMemoryRepository.findByRegistrationId(providerName);

Expand All @@ -76,7 +77,11 @@ public LoginResult login(OauthTokenCommand tokenRequest) {

String accessToken = jwtTokenProvider.createAccessToken(new UserAuthentication(user.getId(), null, null));
tokenRedisRetriever.saveRefreshToken(refreshToken, String.valueOf(user.getId()));
return LoginResult.of(user, accessToken, refreshToken);

boolean isFinishedOnboarding = healthRetriever.existsHealthByUser(user);
boolean isMatched = user.getParentchild() != null && user.getParentchild().isMatched();

return LoginResult.of(user, accessToken, refreshToken, isFinishedOnboarding, isMatched);
}

if (socialPlatform.equals(APPLE)) {
Expand All @@ -89,9 +94,14 @@ public LoginResult login(OauthTokenCommand tokenRequest) {
}

//로그인
updateRefreshToken(userEntity.get(0), refreshToken);
String accessToken = jwtTokenProvider.createAccessToken(new UserAuthentication(userEntity.get(0).getId(),null,null));
return LoginResult.of(userEntity.get(0), accessToken, refreshToken);
User user = userEntity.get(0);
updateRefreshToken(user, refreshToken);
String accessToken = jwtTokenProvider.createAccessToken(new UserAuthentication(user.getId(),null,null));

boolean isFinishedOnboarding = healthRetriever.existsHealthByUser(user);
boolean isMatched = user.getParentchild() != null && user.getParentchild().isMatched();

return LoginResult.of(userEntity.get(0), accessToken, refreshToken, isFinishedOnboarding, isMatched);
}
throw new UserException(INVALID_SOCIAL_PLATFORM);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public OnboardingResult onboardInput(Long userId, OnboardingCommand request){

User user = userRetriever.getUserById(userId);
Health health = parentchildManager.onboardInput(user, request);
healthRetriever.validateHealthByUser(user); // TODO API 중복 호출 예외처리
healthRetriever.validateHealthByUser(user); // API 중복 호출 예외처리
healthRetriever.save(health);

// Slack 신규 유저 알림 전송
Expand Down

0 comments on commit 6995704

Please sign in to comment.