[기능추가][소셜로그인] 기존 로그인 방식을 소셜 로그인 방식으로 전환 #89#90
Conversation
| return memberRepository.save(Member.builder() | ||
| .username(request.getUsername()) | ||
| .socialPlatform(socialPlatform) | ||
| .nickname(request.getNickname()) |
There was a problem hiding this comment.
SignInRequest에 닉네임이랑 생일이 선택으로 되어있던데 만약 null이면 Member에 nullable=false 때문에 저장안되는거 아닌가요?
There was a problem hiding this comment.
추가로 카카오, 네이버에서 주는 birth 데이터 형식이 다를겁니다 프론트랑 형식 어떻게 맞추게되었는지 알려줘용
There was a problem hiding this comment.
Member에서 nullable=true로 변경했습니다.
+) 프론트측에서 YYYY-MM-DD로 받기로 했습니다
| SocialPlatform socialPlatform = SocialPlatform.valueOf(request.getProvider()); | ||
|
|
||
| // DB에서 회원 조회 | ||
| Member member = memberRepository.findByUsernameAndSocialPlatform(request.getUsername(), socialPlatform) |
There was a problem hiding this comment.
한 사람의 다른 플랫폼 로그인은 허용하기로 정했나용?
There was a problem hiding this comment.
프론트, 기획이랑 어떻게 이야기했는지 공유해줘용~
There was a problem hiding this comment.
아니요 허용하지 않도록 했습니다!
Chuseok22
left a comment
There was a problem hiding this comment.
로직은 거의 완벽하네요
최근에 코딩 좀 열심히 한 것 같은데요??ㅋㅋㅋㅋㅋ
| public String getName() { | ||
| return member.getNickname(); | ||
| } |
There was a problem hiding this comment.
public String getName()인데 member.getNickname()을 반환하는거 괜찮나요??
There was a problem hiding this comment.
사용자 본명은 따로 받고있지 않아서 우선 닉네임을 반환하도록 했는데 그러면 이메일이랑 닉네임 중 뭘 반환하는게 좋을까요??
There was a problem hiding this comment.
Class 'CustomOAuth2User' must either be declared abstract or implement abstract method 'getName()' in 'AuthenticatedPrincipal'
이렇게 떠서 getName을 삭제못하는데 getName에 username을 반환할까요?
| @NotBlank(message = "accessToken을 입력하세요") | ||
| @Schema(defaultValue = "ya29.A0ARrdaMExampleAccessToken1234567890") | ||
| private String accessToken; |
There was a problem hiding this comment.
사용자가 로그인하는데 accessToken을 파라미터로 넣어주나요??
이거 어떤건지 설명해줄 수 있어요??
There was a problem hiding this comment.
사용자가 브라우저에서 플랫폼을 선택하고 소셜 플랫폼에서의 인증 절차를 거치는데 여기서의 소셜 플랫폼의 token을 받게됩니다. 이 aceessToken을 프론트가 받아서 백엔드에게 전달해줍니다
| @Schema(description = "생년월일 (선택)", defaultValue = "2004-01-01") | ||
| private String birth; |
There was a problem hiding this comment.
카카오랑 네이버랑 생일을 주는 방식이 다를텐데...
마찬가지로 생일, 출생연도가 다른걸로 알고있는데 프론트랑 어떻게 협의를 봤나요?
There was a problem hiding this comment.
카카오랑 동일하게 YYYY-MM-DD로 받기로 했어요!
| @Schema(description = "닉네임 (선택)", defaultValue = "daily_snap_user") | ||
| private String nickname; |
There was a problem hiding this comment.
여기서 말하는 nickname은 카카오, 네이버 프로필 상 닉네임 맞나요?
There was a problem hiding this comment.
넵 선택적으로 받아오는데 안받아올 경우엔 임의로 설정하도록 합니다
|
|
||
| Optional<Member> findByUsername(String username); | ||
| } No newline at end of file | ||
| Optional<Member> findByUsernameAndSocialPlatform(String username, SocialPlatform socialPlatform); |
There was a problem hiding this comment.
username, socialPlatform으로 동시에 Member를 조회한다는거는 다른 소셜 플랫폼으로 다시 회원가입하면 허용해준다는건데
이거 프론트, 기획이랑 어떻게 합의되었나요?
| SocialPlatform socialPlatform = SocialPlatform.valueOf(request.getProvider()); | ||
|
|
||
| // DB에서 회원 조회 | ||
| Member member = memberRepository.findByUsernameAndSocialPlatform(request.getUsername(), socialPlatform) |
There was a problem hiding this comment.
프론트, 기획이랑 어떻게 이야기했는지 공유해줘용~
| return memberRepository.save(Member.builder() | ||
| .username(request.getUsername()) | ||
| .socialPlatform(socialPlatform) | ||
| .nickname(request.getNickname()) |
There was a problem hiding this comment.
추가로 카카오, 네이버에서 주는 birth 데이터 형식이 다를겁니다 프론트랑 형식 어떻게 맞추게되었는지 알려줘용
| // 응답 헤더에 토큰 설정 | ||
| response.setHeader("Authorization", "Bearer " + accessToken); | ||
| response.setHeader("Refresh-Token", refreshToken); |
There was a problem hiding this comment.
- 네이티브앱에서는 어떻게 토큰을 발급하는지 한번 찾아봐주세요
- 엑세스토큰은
"Authorization"이라는 헤더를 쓰는게 일반적입니당 그런데 리프래시토큰은 어떤 헤더를 일반적으로 쓰는지 한번 찾아봐주세요
There was a problem hiding this comment.
네이티브앱에서는 어떻게 토큰을 발급하는지 한번 찾아봐주세요
네이티브 앱 서비스에서는 소셜 로그인 동작 방식이 이렇게 작동합니다.
프론트엔드
- 사용자가 로그인 버튼 클릭 → 인증 URL로 이동
- 소셜 로그인 페이지에서 사용자 로그인 진행
- 인증 서버에서 access token 받아옴
- 받은 access token을 소셜 리소스 서버에 전송해서 사용자 정보를 조회함
- 사용자 정보로 DB에서 회원 조회 및 생성
백엔드
- 자체 로그인 처리 후 JWT 발급
- JWT를 응답 헤더나 바디에 담아 프론트에 전달
엑세스토큰은 "Authorization"이라는 헤더를 쓰는게 일반적입니당 그런데 리프래시토큰은 어떤 헤더를 일반적으로 쓰는지 한번 찾아봐주세요
일단 엑세스 토큰은 Authorizaion 헤더에 Bearer 방식으로 전달하는 것이 표준 방식이고
리프레스 토큰은
- 헤더에 포함하거나(권장X)
- 쿠키에 포함하거나(권장)
- 응답 바디에 포함하는 방법이 있습니다.
쿠키에 포함해서 반환하는 방법으로 바꿔보도록 하겠습니다!
edb6110 to
0aa2a3b
Compare
0aa2a3b to
59681c0
Compare

✨ 변경 사항
프론트에서 소셜 accessToken을 받아 백엔드에 전달 -> 백엔드에서 프론트로 JWT 발급
MemberService.socialSignIn
멤버 조회 안뜨면 회원가입/ 있으면 로그인으로 수정
SignInRequest 파라미터 수정
Member 엔티티 수정
기타 클래스
✅ 테스트