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: login with google now use new SDK and flow #1108

Merged
merged 12 commits into from
Sep 13, 2023
Merged

refactor: login with google now use new SDK and flow #1108

merged 12 commits into from
Sep 13, 2023

Conversation

mark86092
Copy link
Contributor

@mark86092 mark86092 commented May 13, 2023

Close #

這個 PR 是?

Google Sign-In is set to be deprecated after March 31, 2023
We need to migrate to use the new Google Identity Services for Web solution

怎麼看 code

目前最新的 google login flow 禁止客製化登入按鈕(see ref link),而是必須在畫面上 render "Sign in with Google" 按鈕

因為這件事,我做了幾個改變:

  1. src/components/common/GoogleContextProvider/index.js init SDK 的時候,要提供 callback (L17~L19)
    這個 callback 當 User 按下 "Sign in with Google" 按鈕,完成 Google 登入後,會觸發的
    我們會在這裡觸跟後端換發 token 機制
  2. src/components/common/Auth/GoogleLoginButton.js 由於沒辦法客製化登入按鈕,所以需要透過 google 幫我們 render "Sign in with Google" 按鈕
    • 這個會導致目前的登入畫面 UI 長得很奇怪 (首頁按下登入)
      image
    • 面試頁權限檢查
      image

未來 TODO & 需要幫忙的地方

  1. 需要登入的地方,可以用 GoogleLoginButton 就可以解決了
  2. 需要 Designer 幫忙處理上面兩個醜醜的 UI

Ref

https://developers.google.com/identity/gsi/web/guides/integrate#button_customization

@mark86092 mark86092 marked this pull request as ready for review June 24, 2023 02:39
@barry800414
Copy link
Contributor

@wutingy this may need your help

@wutingy
Copy link
Contributor

wutingy commented Jun 24, 2023

好我看一下

>
<pre>Google 登入</pre>
<GoogleLoginButton onSuccess={() => {}} />
Copy link
Contributor

Choose a reason for hiding this comment

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

可以讓 onSuccess optional 或是 default to () => {},這樣這裡就不需要傳空的進去了

gapi.auth2.init({ client_id: GOOGLE_APP_ID });
const googleAuth = gapi.auth2.getAuthInstance();
setGoogleAuth(googleAuth);
window.onload = function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

需要檢查原本的 onload 嗎?

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

Choose a reason for hiding this comment

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

初步直覺想是這樣

let prevOnload = window.onload;
window.onload = function() {
  if (prevOnload) prevOnload();
  // ...
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

有 addEventListener 可以用,這樣就不用猜 on 的意思了

})
.then(() => authStatus.CONNECTED);
})
.catch(err => authStatus.NOT_AUTHORIZED);
Copy link
Contributor

Choose a reason for hiding this comment

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

不需要沿用之前的 autStatus了嗎

Copy link
Contributor Author

Choose a reason for hiding this comment

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

需要處理,列為之後 TODO 來解

@wutingy
Copy link
Contributor

wutingy commented Jun 26, 2023

https://www.sketch.com/s/4238b387-3057-4a39-9dca-65d936899c69/a/kakVn7Z
@barry800414 @mark86092 補上 UI 囉

@wutingy
Copy link
Contributor

wutingy commented Jun 26, 2023

Screenshot 2023-06-26 at 2 45 16 PM
Screenshot 2023-06-26 at 2 45 45 PM

}}
>
Google 登入
</button>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

發現有現成的 button 可用

setLoginModalDisplayed,
}),
[isLoginModalDisplayed],
);
Copy link
Contributor Author

@mark86092 mark86092 Sep 12, 2023

Choose a reason for hiding this comment

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

React 推薦寫法,contextValue 改動,當且僅當 isLoginModalDisplayed 改動

@mark86092 mark86092 changed the base branch from master to dev September 12, 2023 03:25
@mark86092
Copy link
Contributor Author

@barry800414 @peteranny 改完了,再幫忙測試看看幾個登入點有沒有正常運作

@mark86092 mark86092 changed the title Login with google now use new SDK and flow refactor: login with google now use new SDK and flow Sep 13, 2023
@mark86092 mark86092 merged commit 7c71d49 into goodjoblife:dev Sep 13, 2023
7 checks passed
@mark86092 mark86092 deleted the google-login-new-version branch September 13, 2023 18:40
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.

4 participants