-
Notifications
You must be signed in to change notification settings - Fork 6
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
카카오 사용자를 애플, 구글 사용자로 전환하는 로직 개발 #605
Changes from all commits
a0b3bf1
2a46dec
94b9789
18bde9a
656751b
58ca771
992efb2
acdd8a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,10 @@ | |
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import mouda.backend.auth.business.result.LoginProcessResult; | ||
import mouda.backend.auth.implement.GoogleOauthManager; | ||
import mouda.backend.auth.implement.LoginManager; | ||
import mouda.backend.auth.presentation.request.GoogleOauthReqeust; | ||
import mouda.backend.auth.presentation.request.GoogleOauthRequest; | ||
import mouda.backend.auth.presentation.response.LoginResponse; | ||
import mouda.backend.member.domain.Member; | ||
import mouda.backend.member.domain.OauthType; | ||
|
@@ -17,11 +18,16 @@ public class GoogleAuthService { | |
private final GoogleOauthManager googleOauthManager; | ||
private final LoginManager loginManager; | ||
|
||
public LoginResponse oauthLogin(GoogleOauthReqeust googleOauthReqeust) { | ||
String memberName = googleOauthManager.getMemberName(googleOauthReqeust.idToken()); | ||
String socialLoginId = googleOauthManager.getSocialLoginId(googleOauthReqeust.idToken()); | ||
String accessToken = loginManager.processSocialLogin(OauthType.GOOGLE, socialLoginId); | ||
return new LoginResponse(accessToken); | ||
public LoginResponse oauthLogin(GoogleOauthRequest googleOauthRequest) { | ||
String memberName = googleOauthManager.getMemberName(googleOauthRequest.idToken()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 memberName은 어디서 사용되나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분은 아직 구현이 안된 부분이라서요 😅 |
||
String socialLoginId = googleOauthManager.getSocialLoginId(googleOauthRequest.idToken()); | ||
if (googleOauthRequest.memberId() != null) { | ||
String accessToken = loginManager.updateOauth(googleOauthRequest.memberId(), OauthType.GOOGLE, | ||
socialLoginId); | ||
return new LoginResponse(accessToken); | ||
} | ||
LoginProcessResult loginProcessResult = loginManager.processSocialLogin(OauthType.GOOGLE, socialLoginId); | ||
return new LoginResponse(loginProcessResult.accessToken()); | ||
} | ||
|
||
public Member findMember(String token) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ | |
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import mouda.backend.auth.business.result.LoginProcessResult; | ||
import mouda.backend.auth.implement.KakaoOauthManager; | ||
import mouda.backend.auth.implement.LoginManager; | ||
import mouda.backend.auth.implement.jwt.AccessTokenProvider; | ||
import mouda.backend.auth.presentation.request.OauthRequest; | ||
import mouda.backend.auth.presentation.response.KakaoLoginResponse; | ||
import mouda.backend.auth.presentation.response.LoginResponse; | ||
import mouda.backend.member.domain.LoginDetail; | ||
import mouda.backend.member.domain.Member; | ||
|
@@ -16,19 +18,19 @@ | |
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class KakaoAuthService implements AuthService { | ||
public class KakaoAuthService { | ||
|
||
private final AccessTokenProvider accessTokenProvider; | ||
private final KakaoOauthManager oauthManager; | ||
private final LoginManager loginManager; | ||
private final MemberFinder memberFinder; | ||
private final MemberWriter memberWriter; | ||
|
||
public LoginResponse oauthLogin(OauthRequest oauthRequest) { | ||
public KakaoLoginResponse oauthLogin(OauthRequest oauthRequest) { | ||
String kakaoId = oauthManager.getSocialLoginId(oauthRequest.code()); | ||
String token = loginManager.processSocialLogin(OauthType.KAKAO, kakaoId); | ||
LoginProcessResult loginProcessResult = loginManager.processSocialLogin(OauthType.KAKAO, kakaoId); | ||
|
||
return new LoginResponse(token); | ||
return new KakaoLoginResponse(loginProcessResult.memberId(), loginProcessResult.accessToken()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. accessToken 필요없을 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 우선 memberId 을 포함하여 사용자 전환 테스트하고 반영하겠습니다 ~! |
||
} | ||
|
||
public Member findMember(String token) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package mouda.backend.auth.business.result; | ||
|
||
public record LoginProcessResult( | ||
Long memberId, | ||
String accessToken | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,39 +2,53 @@ | |
|
||
import java.util.Optional; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import mouda.backend.auth.business.result.LoginProcessResult; | ||
import mouda.backend.auth.exception.AuthErrorMessage; | ||
import mouda.backend.auth.exception.AuthException; | ||
import mouda.backend.auth.implement.jwt.AccessTokenProvider; | ||
import mouda.backend.member.domain.LoginDetail; | ||
import mouda.backend.member.domain.Member; | ||
import mouda.backend.member.domain.OauthType; | ||
import mouda.backend.member.implement.MemberFinder; | ||
import mouda.backend.member.implement.MemberWriter; | ||
import mouda.backend.member.infrastructure.MemberRepository; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class LoginManager { | ||
|
||
private final MemberRepository memberRepository; | ||
private final AccessTokenProvider accessTokenProvider; | ||
private final MemberWriter memberWriter; | ||
private final MemberFinder memberFinder; | ||
|
||
public String processSocialLogin(OauthType oauthType, String socialLoginId) { | ||
public LoginProcessResult processSocialLogin(OauthType oauthType, String socialLoginId) { | ||
Optional<Member> member = memberRepository.findByLoginDetail_SocialLoginId(socialLoginId); | ||
log.error("1번"); | ||
|
||
if (member.isPresent()) { | ||
return accessTokenProvider.provide(member.get()); | ||
return new LoginProcessResult(member.get().getId(), accessTokenProvider.provide(member.get())); | ||
} | ||
|
||
if (oauthType == OauthType.KAKAO) { | ||
throw new AuthException(HttpStatus.BAD_REQUEST, AuthErrorMessage.KAKAO_CANNOT_SIGNUP); | ||
} | ||
Comment on lines
+36
to
38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 카카오 SignUp이 안되는 건 비즈니스 로직같은데 어떻게 생각하시나용?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 비즈니스 로직이라는 거 공감해요 ~ 서비스 로직에 추가하고 싶은데 그럴려면 전반적으로 구조를 개선해야해서 시간이 좀 걸릴 것 같아요! 로그인 기능 구현 마무리 후 이슈 파서 진행하겠습니다 ㅎㅎ |
||
log.error("2번"); | ||
Member newMember = Member.builder() | ||
.nickname("nickname") | ||
.loginDetail(new LoginDetail(oauthType, socialLoginId)) | ||
.build(); | ||
memberWriter.append(newMember); | ||
log.error("3번"); | ||
return accessTokenProvider.provide(newMember); | ||
|
||
return new LoginProcessResult(newMember.getId(), accessTokenProvider.provide(newMember)); | ||
} | ||
|
||
public String updateOauth(long memberId, OauthType oauthType, String socialLoginId) { | ||
Member member = memberFinder.find(memberId); | ||
memberWriter.updateLoginDetail(memberId, oauthType, socialLoginId); | ||
|
||
return accessTokenProvider.provide(member); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package mouda.backend.auth.presentation.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record AppleOauthRequest( | ||
Long memberId, | ||
|
||
@NotNull | ||
String code | ||
) { | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package mouda.backend.auth.presentation.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record GoogleOauthRequest( | ||
Long memberId, | ||
|
||
@NotNull | ||
String idToken | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package mouda.backend.auth.presentation.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record OauthRequest( | ||
@NotNull | ||
String code | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package mouda.backend.auth.presentation.response; | ||
|
||
public record KakaoLoginResponse( | ||
Long memberId, | ||
String accessToken | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package mouda.backend.auth.presentation.response; | ||
|
||
public record LoginResponse(String accessToken) { | ||
public record LoginResponse( | ||
String accessToken | ||
) { | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
서비스 단애서 정팩메 쓰는게 컨벤션이었지 않나용?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 감사합니다 👍