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

Refactor #91 소셜 로그인 연동 기능 구현 #91

Merged
merged 23 commits into from
Dec 23, 2024

Conversation

hyxklee
Copy link
Member

@hyxklee hyxklee commented Dec 19, 2024

PR 내용

  • 기존 로그인으로 회원가입한 사용자가 카카오 소셜 로그인으로 연동할 수 있는 기능을 구현했습니다
  • 가입 승인 이후에 JWT Token을 반환해야하기 떄문에 일부 로직을 수정했습니다

PR 세부사항

  • 카카오 소셜 로그인 연동을 위해 social-login , social-register, social-auth 메서드를 사용했습니다

  • 로그인은 login/integrate로 사용되고, auth는 소셜 회원가입시 kakaoId를 프론트 측으로 전달하기 위한 api 입니다

  • 자세한 플로우는 아래와 같습니다

소셜 회원가입

  1. kakao 인증 (social-auth)
{
  "code": 200,
  "message": "소셜 인증에 성공했습니다.",
  "data": {
    "kakaoId": 3765018989
  }
}
  1. 소셜 회원가입 (social-register)
{
  "kakaoId": 3765018989,
  "name": "이강혁",
  "studentId": "20203189",
  "department": "인공지능전공",
  "tel": "010",
  "cardinal": 1,
  "position": "BE"
}
{
  "code": 200,
  "message": "회원 가입 신청이 성공적으로 처리되었습니다.",
  "data": null
}
  1. 소셜 로그인(social-login)
{
  "code": 403,
  "message": "가입 승인이 허가되지 않은 계정입니다.",
  "data": null
}
{
  "code": 200,
  "message": "소셜 로그인에 성공했습니다.",
  "data": {
    "id": 3,
    "kakaoId": 3765018989,
    "status": "LOGIN",
    "accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiW1haWwiOm51bGx9.ROvg88jFJ_D_RN_C69LQXie7uczNurTWEQE4pgCwGzTInKohs5tdOCYKzhaqVx_w",
    "refreshToken": "eyJ0eXAiOiJKV1QiLCJhIiOiJSZWZyZXNoVG9rZW4iLCJpZCI6MywiZXhwIjoxNzM0NTaRkr4XwfLTtyJC0Wow2Obqc8AJfFwoEmROQA"
  }
}

소셜 로그인

연동 전

  1. social-login api 요청
{
  "code": 200,
  "message": "소셜 로그인에 성공했습니다.",
  "data": {
    "id": null,
    "kakaoId": 3765018989,
    "status": "INTEGRATE",
    "accessToken": null,
    "refreshToken": null
  }
}
  1. integrate api 요청
  • 이메일이 틀릴시
{
  "code": 404,
  "message": "존재하지 않는 유저입니다.",
  "data": null
}
  • 비밀번호 오류시
{
  "code": 400,
  "message": "비밀번호가 일치하지 않습니다.",
  "data": null
}
  • 가입 승인이 안될시(정말 만약에)
{
  "code": 403,
  "message": "가입 승인이 허가되지 않은 계정입니다.",
  "data": null
}
  • ID, 비번이 맞을시
{
  "code": 200,
  "message": "소셜 로그인 연동에 성공했습니다.",
  "data": {
    "id": 2,
    "kakaoId": 3765018989,
    "status": "LOGIN",
    "accessToken": "eyJ0eXAiOiJKV1QixMiJ9.eyJzdHJpbmdAc3RyaW5nLmNvbSJ9.eWf6Nvom",
    "refreshToken": "eyJ0eXAiOiJKV1MiJ9.eyJzdWIiOiJSZWZyZXNoVG9rZW4iLCJpZCI6MiwiZXhwIjoxNzM0NTk3MDI3Q"
  }
}

연동 후, 소셜 회원가입 후

{
  "code": 200,
  "message": "소셜 로그인에 성공했습니다.",
  "data": {
    "id": 3,
    "kakaoId": 3765018989,
    "status": "LOGIN",
    "accessToken": "eyJ0eXAiOiJKV1QJIUzUxMiJ9.eyJzdWIiOiJBY2Nlc3NUb2tlbiIsInJvbGUiOiJVU0VSIiwiaWQxbhVULxSGpgCwGzTInKoMEaoFhsqVx_w",
    "refreshToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9..6nF8xnyFN-z4_-wwGuidBdYvxWofy5ZXlFCzwaRkr4XwfLTtyJC0Wow2Obqc8AJfFwoEmROQA"
  }
}

관련 스크린샷


주의사항

  • 소셜 회원가입시 이메일을 입력을 받아야할지 고민입니다. 기존 로그인이 없어진다면 이메일을 쓸 일이 없기 때문
  • 토큰 발급 시기가 변함에 따라 register 메서드를 일부 수정했습니

체크 리스트

  • 리뷰어 설정
  • Assignee 설정
  • Label 설정
  • 제목 양식 맞췄나요? (ex. #0 Feat: 기능 추가)
  • 변경 사항에 대한 테스트

@hyxklee hyxklee requested review from jj0526 and huncozyboy December 19, 2024 07:13
@hyxklee hyxklee self-assigned this Dec 19, 2024
@hyxklee hyxklee changed the title Refactor #80 소셜 로그인 연동 기능 구현 Refactor #91 소셜 로그인 연동 기능 구현 Dec 19, 2024
@hyxklee hyxklee linked an issue Dec 19, 2024 that may be closed by this pull request
@Override
@Transactional
public SocialLoginResponse integrate(NormalLogin dto) {
User user = userGetService.find(dto.email());
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
Member Author

Choose a reason for hiding this comment

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

어떤 부분에서 불일치를 말씀하시는 걸까요??

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
Collaborator

Choose a reason for hiding this comment

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

전화번호나 학번을 이용해서 통합하는건 어려울까요? 현재 사용하는 이메일과 카카오 이메일이 다른 경우도 있을 수 있다 생각해요

Copy link
Member Author

Choose a reason for hiding this comment

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

연동은 kakaoId를 통해서 연동합니다!
여기서 입력 받는 이메일은 사용자 인증을 위해 ID/비번을 받는 부분이라서 연동에 직접적으로 사용되진 않습니다
사용자 인증이 완료되면 null인 kakaoId 컬럼에 데이터가 삽입돼서 연동이 되는 방식입니당

Copy link
Member

@huncozyboy huncozyboy 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 29 to 30
return userRepository.findByKakaoId(kakaoId)
.orElse(null);
Copy link
Member

Choose a reason for hiding this comment

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

현재 kakaoId로 유저를 조회할 때, 값이 없으면 예외처리를 하지않고 null을 반환하는 것이 카카오 ID가 없는 것이 예외상황이 아닌 정상적인 상황으로 간주하고 mapper.toIntegrateResponse(kakaoId)를 이용하신 로직으로 이해했습니다
해당 메서드에 null을 반환하는 대신에 Optional을 사용해주는 방식은 어떨까요 ??

Copy link
Member Author

Choose a reason for hiding this comment

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

Optional로 반환해주는 것이 값의 여부를 구분하기에 더 명시적일 거 같아요
수정하겠습니다!

return CommonResponse.createSuccess(USER_APPLY_SUCCESS.getMessage());
}

@PatchMapping("/integrate")
Copy link
Member

Choose a reason for hiding this comment

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

해당 엔드포인트도좋지만 동사보다는 명사의 형태로 설계하는 것이 지향된다고 알고있어,
social-link나 kakao-link와 같은 형태로 개선하면 더 RESTful한 설계가 될거같은데 어떻게 생각하실까요 ??

Copy link
Member Author

Choose a reason for hiding this comment

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

앗 그렇네요 좀 더 좋은 엔드포인트로 고민해보겠습니닷

@Override
@Transactional
public SocialLoginResponse integrate(NormalLogin dto) {
User user = userGetService.find(dto.email());
Copy link
Collaborator

Choose a reason for hiding this comment

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

아! 이메일이 일치하는 경우만 통합되네요

@Override
@Transactional
public SocialLoginResponse integrate(NormalLogin dto) {
User user = userGetService.find(dto.email());
Copy link
Collaborator

Choose a reason for hiding this comment

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

전화번호나 학번을 이용해서 통합하는건 어려울까요? 현재 사용하는 이메일과 카카오 이메일이 다른 경우도 있을 수 있다 생각해요

) {
}

public record Register(
Copy link
Collaborator

Choose a reason for hiding this comment

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

SignUp과 Register 이름이 헷갈릴거같은데 kakao를 앞에 추가하는건 어떤가요?

Copy link
Member Author

Choose a reason for hiding this comment

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

socialRegister로 수정하겠습니당

@huncozyboy
Copy link
Member

고생하셨어요 문제 없어보입니다 !

Copy link
Collaborator

@jj0526 jj0526 left a comment

Choose a reason for hiding this comment

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

수고하셨어요! 연동할땐 카카오 로그인과 기존 로그인을 같이 받는거였네요

@hyxklee hyxklee merged commit 1c79845 into develop Dec 23, 2024
2 checks passed
@hyxklee hyxklee deleted the refactor/#88/소셜-로그인-수정 branch December 23, 2024 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor #88 카카오 소셜 로그인 연동을 위한 로직 수정
3 participants