-
Notifications
You must be signed in to change notification settings - Fork 10
[9주차/윤샘] 워크북 제출합니다 #59
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
base: yunsam/main
Are you sure you want to change the base?
Changes from all commits
0de3dd8
2125fd8
0320d72
1476650
ee28a93
7936273
28675ac
a4107b6
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 |
|---|---|---|
|
|
@@ -36,6 +36,8 @@ | |
| import umc.domain.term.exception.TermException; | ||
| import umc.domain.term.exception.code.TermErrorCode; | ||
| import umc.domain.term.repository.TermRepository; | ||
| import umc.global.security.entity.AuthMember; | ||
| import umc.global.security.util.JwtUtil; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
@@ -55,6 +57,7 @@ public class MemberService { | |
| private final TermRepository termRepository; | ||
| private final MemberPreferredCategoryRepository memberPreferredCategoryRepository; | ||
| private final TermAgreementRepository termAgreementRepository; | ||
| private final JwtUtil jwtUtil; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public MemberResDTO.GetInfo getInfo(Long memberId) { | ||
|
|
@@ -199,4 +202,18 @@ private void validateTermExist( | |
| throw new TermException(TermErrorCode.TERM_MASTER_DATA_NOT_FOUND); | ||
| } | ||
| } | ||
|
|
||
| @Transactional | ||
| public MemberResDTO.Login login(MemberReqDTO.Login request){ | ||
| Member member = memberRepository.findByEmail(request.email()) | ||
| .orElseThrow(() -> new MemberException(MemberErrorCode.LOGIN_FAILED)); | ||
|
|
||
| if(!passwordEncoder.matches(request.paassword(), member.getPassword())){ | ||
| throw new MemberException(MemberErrorCode.LOGIN_FAILED); | ||
| } | ||
|
|
||
| String accessToken = jwtUtil.createAccessToken(new AuthMember(member)); | ||
|
|
||
| return MemberConverter.toLogin(accessToken); | ||
| } | ||
|
Comment on lines
+206
to
+218
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. 로그인 로직에서 먼저 사용자의 이메일을 검증하고, 비밀번호를 해싱해서 기존 값이랑 검증하는 흐름이 명확하게 잘 보입니다! 또 이메일이 존재하지 않을 때와 비밀번호가 틀렸을 때 에러메시지를 통일시키신 것을 보니 윤샘이 보안도 신경써주신 것 같다고 생각했습니다. 저는 사용자 검증 로직을 Spring Security의 물론 윤샘처럼 구현하는 것도 가독성 측면에서의 장점도 있는 것 같습니다. 다만 이미 Spring Security를 도입하신 만큼 기능을 활용하는 것도 고려해보시면 좋을 것 같습니다!! 😊 (아 그리고 로그인 요청 dto에 필드값 오타가 있습니다 ㅎㅎ) |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package umc.global.security.dto; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import umc.domain.member.enums.SocialProvider; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class KakaoDTO implements OAuthDTO{ | ||
|
|
||
| private final String id; | ||
| private final String email; | ||
| private final String name; | ||
|
|
||
| @Override | ||
| public SocialProvider getSocialProvider(){ | ||
| return SocialProvider.KAKAO; | ||
| } | ||
|
|
||
| @Override | ||
| public String getSocialId(){ | ||
| return id; | ||
| } | ||
|
|
||
| @Override | ||
| public String getSocialEmail(){ | ||
| return email; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName(){ | ||
| return name; | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package umc.global.security.dto; | ||
|
|
||
| import umc.domain.member.enums.SocialProvider; | ||
|
|
||
| public interface OAuthDTO { | ||
| SocialProvider getSocialProvider(); | ||
| String getSocialId(); | ||
| String getSocialEmail(); | ||
| String getName(); | ||
| } |
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.
윤샘이 해당 부분에 더미를 두었던 이유를 추적해보며 왜 Member 엔티티에서 nullable=false를 이렇게 많이 지정했지? 생각해보았습니다.
이건 약간 OAuth 로그인 성공 = 서비스 가입 완료라는 시선이 잡혀있어서 그런 것 같습니다! (아님말고)
이미지의 와이어프레임처럼 서비스에서 필요한 추가적인 정보를 받아야 할 경우
방법 A. OAuth 성공 시 Member를 먼저 만든다
→ profileCompleted=false 또는 status=PENDING_PROFILE
→ 추가 정보 입력 완료 시 ACTIVE
방법 B. OAuth 성공 시 Member를 아직 만들지 않는다
→ socialUid/email 등을 임시 토큰이나 세션에 담음
→ 추가 정보 입력까지 끝난 뒤 Member 생성
위의 방법등을 사용하게 됩니다.
이렇게 보면 회원가입 상태 모델링 자체에서 비밀번호/생년월일/주소 없이 소셜 회원을 만들 수 있게 하거나, 아예 생성 시점을 뒤로 미루는 방식도 가능할 것 같은데 이 부분은 어떻게 생각하시는지 궁금합니다!