codestates / codestates/Touch

[Error handling] 구글 로그인 구현 시 유저의 이메일 정보를 받아오지 못했던 오류

Open
#65 0 comments 0 reactions 0 assignees View on GitHub
Complete error
Dominant language
JavaScript
Stars
0
Forks
1
PR merge metrics
No merged PRs in 30d

Description

> ### 어떤 에러인가요?
> 구글 oauth2 로그인 시 유저의 이메일 정보를 받아오지 못했던 오류입니다.
>
> ### 에러 메시지
> ```shell
> // 오류메세지는 따로 없음, 있다면 데이터베이스에 받아온 유저의 이메일을 등록해야하는데 이메일을 받아오지 못해 {where: {email}} 에서 email 이 undefined 라고 떴던 부분.
> ```
>
> ### 에러 핸들링 방법
> 아래 상세히 설명했듯이 scope(범위) 설정을 조금 바꿔주면 해결되는 문제였습니다.
>
> ```js
> // 구글로 authCode 요청시 url 주소의 scope 를
> scope=https://www.googleapis.com/auth/userinfo.profile&include_granted_scopes=true
> // 에서
> scope=https://www.googleapis.com/auth/userinfo.email&include_granted_scopes=true
> // 로 변경
> ```
>
> 위 코드에서, scope 부분을 보면 기존에는 userinfo.profile 이라고 되어있는데 이 부분을 userinfo.email 이라고 수정해줬더니 해결되었습니다.
> (보통 profile에 이메일이 다 포함되어 있어서 profile로 해줬던 부분인데 profile에 이메일이 포함되지 않은 경우도 있는 것 같습니다. 혹은 공개 정보 중 유저별로 공개정보에 이메일을 포함시키지 않은 경우일 수 도 있습니다.)
>
> ### 에러 핸들링을 위해 참고한 레퍼런스 링크
> [링크](https://developers.google.com/identity/protocols/oauth2/scopes)
> 위 링크의 Google OAuth2 API , v2 부분을 보면 범위 설정 관련 정보가 나온다

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.