Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#48 [Refactor] Auth 관련 에러처리 리팩토링 #49

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.puzzling.puzzlingServer.api.member.auth;

public enum SocialPlatform {
KAKAO,
NAVER
KAKAO
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,50 @@ public AuthResponseDto socialLogin(String socialAccessToken, AuthRequestDto auth
throw new BadRequestException(ErrorStatus.VALIDATION_REQUEST_MISSING_EXCEPTION.getMessage());
}

SocialPlatform socialPlatform = SocialPlatform.valueOf(authRequestDto.getSocialPlatform());
SocialInfoDto socialData = getSocialData(socialPlatform, socialAccessToken);
try {
SocialPlatform socialPlatform = SocialPlatform.valueOf(authRequestDto.getSocialPlatform());

String refreshToken = jwtTokenProvider.generateRefreshToken();
SocialInfoDto socialData = getSocialData(socialPlatform, socialAccessToken);

Boolean isExistUser = isMemberBySocialId(socialData.getId());
String refreshToken = jwtTokenProvider.generateRefreshToken();

// 신규 유저 저장
if (!isExistUser.booleanValue()) {
Member member = Member.builder()
.name(socialData.getNickname())
.socialPlatform(socialPlatform)
.socialId(socialData.getId())
.build();
Boolean isExistUser = isMemberBySocialId(socialData.getId());

memberRepository.save(member);
// 신규 유저 저장
if (!isExistUser.booleanValue()) {
Member member = Member.builder()
.name(socialData.getNickname())
.socialPlatform(socialPlatform)
.socialId(socialData.getId())
.build();

member.updateRefreshToken(refreshToken);
memberRepository.save(member);

}
else findMemberBySocialId(socialData.getId()).updateRefreshToken(refreshToken);
member.updateRefreshToken(refreshToken);

}
else findMemberBySocialId(socialData.getId()).updateRefreshToken(refreshToken);

// socialId를 통해서 등록된 유저 찾기
Member signedMember = findMemberBySocialId(socialData.getId());
// socialId를 통해서 등록된 유저 찾기
Member signedMember = findMemberBySocialId(socialData.getId());

Authentication authentication = new UserAuthentication(signedMember.getId(), null, null);
Authentication authentication = new UserAuthentication(signedMember.getId(), null, null);

String accessToken = jwtTokenProvider.generateAccessToken(authentication);
String accessToken = jwtTokenProvider.generateAccessToken(authentication);

String name = signedMember.getName();
List<UserProject> userProjectList = userProjectRepository.findByMemberIdOrderByCreatedAtDesc(signedMember.getId());
String name = signedMember.getName();
List<UserProject> userProjectList = userProjectRepository.findByMemberIdOrderByCreatedAtDesc(signedMember.getId());

if (userProjectList.isEmpty()) {
return AuthResponseDto.of(name, signedMember.getId(),null,
if (userProjectList.isEmpty()) {
return AuthResponseDto.of(name, signedMember.getId(),null,
accessToken, refreshToken, !isExistUser);
}
return AuthResponseDto.of(name, signedMember.getId(), userProjectList.get(0).getProject().getId(),
accessToken, refreshToken, !isExistUser);

} catch (IllegalArgumentException ex) {
throw new IllegalArgumentException(ErrorStatus.ANOTHER_ACCESS_TOKEN.getMessage());
}
return AuthResponseDto.of(name, signedMember.getId(), userProjectList.get(0).getProject().getId(),
accessToken, refreshToken, !isExistUser);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum ErrorStatus {
VALIDATION_REQUEST_MISSING_EXCEPTION("요청값이 입력되지 않았습니다."),
VALIDATION_NAMING_EXCEPTION("이모지 및 특수기호 입력은 불가능합니다. 제외하여 입력해 주세요."),
NO_TOKEN("토큰을 넣어주세요."),
ANOTHER_ACCESS_TOKEN("소셜 타입이 잘못되었습니다."),
ANOTHER_ACCESS_TOKEN("지원하지 않는 소셜 플랫폼입니다."),
VALIDATION_PATH_MISSING_EXCEPTION("요청하는 path에 넘겨주는 variable이 입력되지 않았습니다."),

/**
Expand Down
Loading