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

구글 로그인, apple로그인 구현, 기존 카카오톡 로그인 사용자를 위한 데이터 이전 로직 구현 #606

Merged
merged 36 commits into from
Oct 8, 2024

Conversation

jaeml06
Copy link
Contributor

@jaeml06 jaeml06 commented Oct 4, 2024

PR의 목적이 무엇인가요?

기존의 카카오톡 로그인을 더이상 지원하지 않고 apple로그인과 구글 로그인을 지원하게 되었다. 이를 구현하고, 기존 카카오톡 로그인 사용자를 위해 데이터 이전 로직이 필요하다.

이슈 ID는 무엇인가요?

설명

구글 로그인과 애플 로그인을 구현하였다. 애플 로그인의 경우 기존 카카오톡 로그인과 같은 oauth2.0을 수동으로 구현하였다.
흐름은

  1. apple 로그인 하기 버튼 클릭
  2. apple 로그인 페이지로 이동
  3. 로그인
  4. 애플로서 리다이렉션 url에 code를 쿼리로 붙여서 전달
  5. OAuthLoginPage 컴포넌트에서 url에서 code를 추출하여 서버로 전달
  6. 서버에서 access_token을 받아옴
  7. 로그인 완료
    와 같이 진행된다.

이와 다르게 구글 로그인에 경우, oauth2.0을 수동으로 구현할 수 있었으나, 서버에서 code를 검증할 때 문제가 파악할 수 없는 문제가 발생하여
https://developers.google.com/identity/gsi/web/guides/overview
다음 링크를 통한 방식으로 구현하게 되었다.
GIS(Google Identity Services)를 이용하여 로그인을 하는데 설명을 읽어보면

Google 계정으로 로그인은 맞춤설정된 버튼, 원탭, 자동 로그인, 승인 등 여러 관련 서비스를 포괄하는 단일 SDK를 제공합니다. 표준 OAuth 및 OpenID Connect 프로토콜보다 더 쉽고 안전한 환경을 개발자에게 제공하는 동시에 더 원활한 사용자 환경을 제공하는 것을 목표로 합니다.

라고한다. 실제로 로그인 버튼을 구글에서 제공하는 버튼으로 넣기만 하면 자동으로 JWT로 암호화된 idToken을 가져온다.
이 idToken을 서버로 보내면 로그인이 된다.

다만 현재 이 방식에서도 문제가 발생한다.
간혈적으로 구글 로그인 버튼이 사라지는 문제인데
dev.mouda.site에서 처음 접속했을 때는 정상적으로 로그인버튼이 보인다. 이때 새로고침을 하게 되면 로그인 버튼이 사라지게 된다. 그리고 개발자 모드를 킨 상태에서는 로그인 버튼이 보인다. 해당 문제가 발생하는데 도데체 왜 이런 문제가
발생하는 문제가 생긴다.
프론트 인원 중 시간이 있는 인원에게 도움을 청한다. PR을 쓰는 시점에도 왜 이런 문제가 발생하는지 모르겠다.

2024-10-05.12.mp4

다음은 기존 사용자의 데이터 이전을 위한 로직이다.
해당 로직은 아래의 문서로 제출하겠다.
https://successful-jeep-771.notion.site/e598b8b22f8643eea759859d0df35aad?pvs=4

질문 혹은 공유 사항 (Optional)

간혈적으로 구글 로그인 버튼이 사라지는 문제인데
dev.mouda.site에서 처음 접속했을 때는 정상적으로 로그인버튼이 보인다. 이때 새로고침을 하게 되면 로그인 버튼이 사라지게 된다. 그리고 개발자 모드를 킨 상태에서는 로그인 버튼이 보인다. 해당 문제가 발생하는데 도데체 왜 이런 문제가
발생하는 문제가 생긴다.
프론트 인원 중 시간이 있는 인원에게 도움을 청한다. PR을 쓰는 시점에도 왜 이런 문제가 발생하는지 모르겠다.

역시 stackoverflow는 신이다. 찬양하도록 하자
https://stackoverflow.com/questions/70993933/why-does-the-sign-in-with-google-button-disappear-after-i-render-it-the-second-t
이것으로 해결할 수 있는지 일요일쯤 다시 테스트해보도록 하겠다.

cys4585 and others added 30 commits September 30, 2024 15:55
@jaeml06 jaeml06 added FE 프론트엔드 관련 이슈입니다. 🌱 기능추가 feature (새로운 기능 구현) labels Oct 4, 2024
@jaeml06 jaeml06 requested review from ss0526100 and cys4585 October 4, 2024 15:51
@jaeml06 jaeml06 self-assigned this Oct 4, 2024
@Mingyum-Kim
Copy link
Contributor

오 그래도 문제 해결 방법을 찾은 것 같네요
해결 되면 다시 연동 테스트 해 보아요 ~

@hoyeonyy
Copy link
Contributor

hoyeonyy commented Oct 7, 2024

지원 가능한 백엔드 등장

Copy link
Contributor

@cys4585 cys4585 left a comment

Choose a reason for hiding this comment

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

구글 oauth 관련 문제로 고생 많으셨습니다. 👍

Comment on lines 7 to 12
export const getLastDarakbangId = () => {
const lastDarakbangId = localStorage.getItem(LAST_DARAKBANG_ID_KEY);
if (!lastDarakbangId || process.env.MSW === 'true') return null;
if (!lastDarakbangId) return null;
else if (process.env.MSW === 'true') return 0;
return +lastDarakbangId;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

msw 환경에서 반환값을 0으로 별도 처리한 이유가 있나요??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0번째 다락방을 접속한다는 의미였습니다. MSW에서 접속하는 다락방이 0입니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

만약 기존 localStorage에 0이 아니라 다른 값이 저장되어있다면 제대로 모킹되지 않습니다.

Comment on lines 16 to 19
window.google.accounts.id.renderButton(
document.getElementById('g_id_signin'),
{ theme: 'outline', size: 'large', width: 269 },
);
Copy link
Contributor

Choose a reason for hiding this comment

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

useRef 훅을 써보는 건 어떨까요???

Copy link
Contributor Author

Choose a reason for hiding this comment

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

확인해볼게요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

사용했는데 그것보다 html 스크립트가 google login관련 코드가 준비되기전에 버튼을 렌더하려는 문제 때문에 버튼이 그려지지 않는 것 같아요

@jaeml06 jaeml06 merged commit 8a8bd65 into develop-frontend Oct 8, 2024
1 check passed
@ss0526100 ss0526100 deleted the feature/#553 branch October 17, 2024 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FE 프론트엔드 관련 이슈입니다. 🌱 기능추가 feature (새로운 기능 구현)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants