-
Notifications
You must be signed in to change notification settings - Fork 11
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
refactor: login with google now use new SDK and flow #1108
Conversation
@wutingy this may need your help |
好我看一下 |
> | ||
<pre>Google 登入</pre> | ||
<GoogleLoginButton onSuccess={() => {}} /> |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要檢查原本的 onload 嗎?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要...我想想怎麼改,或有建議怎麼做嗎?
There was a problem hiding this comment.
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();
// ...
};
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要沿用之前的 autStatus了嗎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要處理,列為之後 TODO 來解
}} | ||
> | ||
Google 登入 | ||
</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
發現有現成的 button 可用
setLoginModalDisplayed, | ||
}), | ||
[isLoginModalDisplayed], | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React 推薦寫法,contextValue 改動,當且僅當 isLoginModalDisplayed
改動
@barry800414 @peteranny 改完了,再幫忙測試看看幾個登入點有沒有正常運作 |
Close #
這個 PR 是?
怎麼看 code
目前最新的 google login flow 禁止客製化登入按鈕(see ref link),而是必須在畫面上 render "Sign in with Google" 按鈕
因為這件事,我做了幾個改變:
src/components/common/GoogleContextProvider/index.js
init SDK 的時候,要提供 callback (L17~L19)這個 callback 當 User 按下 "Sign in with Google" 按鈕,完成 Google 登入後,會觸發的
我們會在這裡觸跟後端換發 token 機制
src/components/common/Auth/GoogleLoginButton.js
由於沒辦法客製化登入按鈕,所以需要透過 google 幫我們 render "Sign in with Google" 按鈕未來 TODO & 需要幫忙的地方
GoogleLoginButton
就可以解決了Ref
https://developers.google.com/identity/gsi/web/guides/integrate#button_customization