feat: support google one tap signin (#2131)

* feat: add google one tap support

* feat: gofumpt

* feat: add google provider rule conf

* feat: update i18n
This commit is contained in:
haiwu
2023-07-25 15:49:15 +08:00
committed by GitHub
parent bfe8e5f3e7
commit d1f88ca9b8
17 changed files with 170 additions and 14 deletions

View File

@ -14,6 +14,9 @@
import {createButton} from "react-social-login-buttons";
import {StaticBaseUrl} from "../Setting";
import {useGoogleOneTapLogin} from "react-google-one-tap-login";
import * as Setting from "../Setting";
import * as Provider from "./Provider";
function Icon({width = 24, height = 24, color}) {
return <img src={`${StaticBaseUrl}/buttons/google.svg`} alt="Sign in with Google" />;
@ -29,4 +32,29 @@ const config = {
const GoogleLoginButton = createButton(config);
export function GoogleOneTapLoginVirtualButton(prop) {
const application = prop.application;
const providerConf = prop.providerConf;
// https://stackoverflow.com/questions/62281579/google-one-tap-sign-in-ui-not-displayed-after-clicking-the-close-button
// document.cookie = "g_state=;path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT";
useGoogleOneTapLogin({
googleAccountConfigs: {
client_id: providerConf.provider.clientId,
},
onError: (error) => {
Setting.showMessage("error", error);
},
onSuccess: (response) => {
const code = "GoogleIdToken-" + JSON.stringify(response);
const authUrlParams = new URLSearchParams(Provider.getAuthUrl(application, providerConf.provider, "signup"));
const state = authUrlParams.get("state");
let redirectUri = authUrlParams.get("redirect_uri");
redirectUri = `${redirectUri}?state=${state}&code=${encodeURIComponent(code)}`;
Setting.goToLink(redirectUri);
},
disableCancelOnUnmount: true,
});
}
export default GoogleLoginButton;