diff --git a/src/common/component/GoogleLoginButton.tsx b/src/common/component/GoogleLoginButton.tsx index fc4f924a..aaa4c650 100644 --- a/src/common/component/GoogleLoginButton.tsx +++ b/src/common/component/GoogleLoginButton.tsx @@ -1,5 +1,5 @@ import { FC, useEffect, useState } from "react"; -import { useGoogleLogin, GoogleOAuthProvider } from "@react-oauth/google"; +import { GoogleLogin, GoogleOAuthProvider } from "@react-oauth/google"; import toast from "react-hot-toast"; import styled from "styled-components"; import { KEY_LOCAL_MAGIC_TOKEN } from "../../app/config"; @@ -8,6 +8,7 @@ import Button from "./styled/Button"; import { useLoginMutation } from "../../app/services/auth"; const StyledSocialButton = styled(Button)` + position: relative; width: 100%; margin-bottom: 16px; display: flex; @@ -21,6 +22,14 @@ const StyledSocialButton = styled(Button)` width: 24px; height: 24px; } + .invisible { + opacity: 0; + position: absolute; + width: 100%; + iframe { + width: 100% !important; + } + } `; interface Props { @@ -30,24 +39,10 @@ interface Props { type?: "login" | "register"; } -const GoogleLogin: FC = ({ type = "login", loaded, loadError }) => { +const GoogleLoginInner: FC = ({ type = "login", loaded, loadError }) => { const [login, { isSuccess, isLoading, error }] = useLoginMutation(); //拿本地存的magic token const magic_token = localStorage.getItem(KEY_LOCAL_MAGIC_TOKEN); - const googleLogin = useGoogleLogin({ - // flow: "auth-code", - onSuccess: (res) => { - if ("code" in res) { - console.error(`google login failed: ${res.code}`); - } else { - login({ - magic_token, - id_token: res.access_token, - type: "google" - }); - } - } - }); useEffect(() => { if (isSuccess) { toast.success("Login Successfully"); @@ -69,12 +64,20 @@ const GoogleLogin: FC = ({ type = "login", loaded, loadError }) => { return; } }, [error]); - const handleGoogleLogin = () => { - googleLogin(); - }; return ( - + +
+ { + login({ + magic_token, + id_token: res.credential, + type: "google" + }); + }} + /> +
{loadError ? "Script Load Error!" @@ -98,7 +101,7 @@ const GoogleLoginButton: FC = ({ type = "login", clientId }) => { }} clientId={clientId} > - + ); };