Skip to content

Comments

[기능추가][소셜로그인] 기존 로그인 방식을 소셜 로그인 방식으로 전환 #89#90

Merged
Chuseok22 merged 5 commits intotestfrom
hyerim/feat-14-social-login
Jul 16, 2025
Merged

[기능추가][소셜로그인] 기존 로그인 방식을 소셜 로그인 방식으로 전환 #89#90
Chuseok22 merged 5 commits intotestfrom
hyerim/feat-14-social-login

Conversation

@HyerimH
Copy link
Collaborator

@HyerimH HyerimH commented Jun 27, 2025

✨ 변경 사항


프론트에서 소셜 accessToken을 받아 백엔드에 전달 -> 백엔드에서 프론트로 JWT 발급

MemberService.socialSignIn
멤버 조회 안뜨면 회원가입/ 있으면 로그인으로 수정

SignInRequest 파라미터 수정

  • provider(카카오, 구글)
  • accessToken
  • username
  • birth(선택)
  • nickname(선택)

Member 엔티티 수정

  • Enum 클래스 socialPlatform 추가

기타 클래스

  • 소셜 로그인에 맞게 수정

✅ 테스트


  • 수동 테스트 완료
  • 테스트 코드 완료

@HyerimH HyerimH changed the title [기능추가][소셜로그인] 인기 게시물 피드백 반영 #89 [기능추가][소셜로그인] 기존 로그인 방식을 소셜 로그인 방식으로 전환 #90 Jul 2, 2025
@HyerimH HyerimH changed the title [기능추가][소셜로그인] 기존 로그인 방식을 소셜 로그인 방식으로 전환 #90 [기능추가][소셜로그인] 기존 로그인 방식을 소셜 로그인 방식으로 전환 #89 Jul 2, 2025
@HyerimH HyerimH changed the base branch from main to test July 2, 2025 13:15
Copy link
Collaborator

@nayoung04 nayoung04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다~

return memberRepository.save(Member.builder()
.username(request.getUsername())
.socialPlatform(socialPlatform)
.nickname(request.getNickname())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SignInRequest에 닉네임이랑 생일이 선택으로 되어있던데 만약 null이면 Member에 nullable=false 때문에 저장안되는거 아닌가요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가로 카카오, 네이버에서 주는 birth 데이터 형식이 다를겁니다 프론트랑 형식 어떻게 맞추게되었는지 알려줘용

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Member에서 nullable=true로 변경했습니다.
+) 프론트측에서 YYYY-MM-DD로 받기로 했습니다

SocialPlatform socialPlatform = SocialPlatform.valueOf(request.getProvider());

// DB에서 회원 조회
Member member = memberRepository.findByUsernameAndSocialPlatform(request.getUsername(), socialPlatform)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한 사람의 다른 플랫폼 로그인은 허용하기로 정했나용?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

프론트, 기획이랑 어떻게 이야기했는지 공유해줘용~

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아니요 허용하지 않도록 했습니다!

Copy link
Contributor

@Chuseok22 Chuseok22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로직은 거의 완벽하네요

최근에 코딩 좀 열심히 한 것 같은데요??ㅋㅋㅋㅋㅋ

Comment on lines +33 to 35
public String getName() {
return member.getNickname();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public String getName()인데 member.getNickname()을 반환하는거 괜찮나요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용자 본명은 따로 받고있지 않아서 우선 닉네임을 반환하도록 했는데 그러면 이메일이랑 닉네임 중 뭘 반환하는게 좋을까요??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이메일로 갑시다

만약 위쪽에 public String getUsername()이 있다면 public String getName() 메서드는 삭제합시다

스크린샷 2025-07-16 오후 3 58 11

Copy link
Collaborator Author

@HyerimH HyerimH Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class 'CustomOAuth2User' must either be declared abstract or implement abstract method 'getName()' in 'AuthenticatedPrincipal'
이렇게 떠서 getName을 삭제못하는데 getName에 username을 반환할까요?

Comment on lines +24 to +26
@NotBlank(message = "accessToken을 입력하세요")
@Schema(defaultValue = "ya29.A0ARrdaMExampleAccessToken1234567890")
private String accessToken;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용자가 로그인하는데 accessToken을 파라미터로 넣어주나요??

이거 어떤건지 설명해줄 수 있어요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용자가 브라우저에서 플랫폼을 선택하고 소셜 플랫폼에서의 인증 절차를 거치는데 여기서의 소셜 플랫폼의 token을 받게됩니다. 이 aceessToken을 프론트가 받아서 백엔드에게 전달해줍니다

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음.... 로직 이거 아닌데

Comment on lines +28 to +29
@Schema(description = "생년월일 (선택)", defaultValue = "2004-01-01")
private String birth;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

카카오랑 네이버랑 생일을 주는 방식이 다를텐데...

마찬가지로 생일, 출생연도가 다른걸로 알고있는데 프론트랑 어떻게 협의를 봤나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

카카오랑 동일하게 YYYY-MM-DD로 받기로 했어요!

Comment on lines +31 to +32
@Schema(description = "닉네임 (선택)", defaultValue = "daily_snap_user")
private String nickname;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 말하는 nickname은 카카오, 네이버 프로필 상 닉네임 맞나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 선택적으로 받아오는데 안받아올 경우엔 임의로 설정하도록 합니다


Optional<Member> findByUsername(String username);
} No newline at end of file
Optional<Member> findByUsernameAndSocialPlatform(String username, SocialPlatform socialPlatform);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

username, socialPlatform으로 동시에 Member를 조회한다는거는 다른 소셜 플랫폼으로 다시 회원가입하면 허용해준다는건데

이거 프론트, 기획이랑 어떻게 합의되었나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

허용하지 않기로 했습니다!

SocialPlatform socialPlatform = SocialPlatform.valueOf(request.getProvider());

// DB에서 회원 조회
Member member = memberRepository.findByUsernameAndSocialPlatform(request.getUsername(), socialPlatform)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

프론트, 기획이랑 어떻게 이야기했는지 공유해줘용~

return memberRepository.save(Member.builder()
.username(request.getUsername())
.socialPlatform(socialPlatform)
.nickname(request.getNickname())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가로 카카오, 네이버에서 주는 birth 데이터 형식이 다를겁니다 프론트랑 형식 어떻게 맞추게되었는지 알려줘용

Comment on lines 59 to 66
// 응답 헤더에 토큰 설정
response.setHeader("Authorization", "Bearer " + accessToken);
response.setHeader("Refresh-Token", refreshToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 네이티브앱에서는 어떻게 토큰을 발급하는지 한번 찾아봐주세요
  2. 엑세스토큰은 "Authorization"이라는 헤더를 쓰는게 일반적입니당 그런데 리프래시토큰은 어떤 헤더를 일반적으로 쓰는지 한번 찾아봐주세요

Copy link
Collaborator Author

@HyerimH HyerimH Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네이티브앱에서는 어떻게 토큰을 발급하는지 한번 찾아봐주세요

네이티브 앱 서비스에서는 소셜 로그인 동작 방식이 이렇게 작동합니다.
프론트엔드

  • 사용자가 로그인 버튼 클릭 → 인증 URL로 이동
  • 소셜 로그인 페이지에서 사용자 로그인 진행
  • 인증 서버에서 access token 받아옴
  • 받은 access token을 소셜 리소스 서버에 전송해서 사용자 정보를 조회함
  • 사용자 정보로 DB에서 회원 조회 및 생성

백엔드

  • 자체 로그인 처리 후 JWT 발급
  • JWT를 응답 헤더나 바디에 담아 프론트에 전달

엑세스토큰은 "Authorization"이라는 헤더를 쓰는게 일반적입니당 그런데 리프래시토큰은 어떤 헤더를 일반적으로 쓰는지 한번 찾아봐주세요
일단 엑세스 토큰은 Authorizaion 헤더에 Bearer 방식으로 전달하는 것이 표준 방식이고

리프레스 토큰은

  1. 헤더에 포함하거나(권장X)
  2. 쿠키에 포함하거나(권장)
  3. 응답 바디에 포함하는 방법이 있습니다.

쿠키에 포함해서 반환하는 방법으로 바꿔보도록 하겠습니다!

@HyerimH HyerimH force-pushed the hyerim/feat-14-social-login branch from 0aa2a3b to 59681c0 Compare July 10, 2025 15:26
@Chuseok22 Chuseok22 merged commit 816a44c into test Jul 16, 2025
1 check passed
Chuseok22 added a commit that referenced this pull request Jul 16, 2025
[기능추가][소셜로그인] 기존 로그인 방식을 소셜 로그인 방식으로 전환 #89 (#90)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants