import { FC, Suspense, useEffect, useState } from "react"; import toast from "react-hot-toast"; import { useTranslation } from "react-i18next"; import { GoogleLogin, GoogleOAuthProvider } from "@react-oauth/google"; import { KEY_LOCAL_MAGIC_TOKEN } from "@/app/config"; import { useLoginMutation } from "@/app/services/auth"; import IconGoogle from "@/assets/icons/google.svg"; import Button from "./styled/Button"; interface Props { loadError?: boolean; loaded?: boolean; clientId?: string; type?: "login" | "register"; } const GoogleLoginInner: FC = ({ type = "login", loaded, loadError }) => { const { t } = useTranslation("auth"); const { t: ct } = useTranslation(); const [login, { isSuccess, isLoading, error }] = useLoginMutation(); //拿本地存的magic token const magic_token = localStorage.getItem(KEY_LOCAL_MAGIC_TOKEN); useEffect(() => { if (isSuccess) { toast.success(ct("tip.login")); // navigateTo("/"); } }, [isSuccess]); useEffect(() => { if (error && "status" in error) { switch (error.status) { case 410: toast.error( "No associated account found, please contact user admin for an invitation link to join." ); break; default: toast.error("Something Error"); break; } } }, [error]); return ( ); }; const GoogleLoginButton: FC = ({ type = "login", clientId }) => { const [scriptLoaded, setScriptLoaded] = useState(false); const [hasError, setHasError] = useState(false); if (!clientId) return null; return ( loading...}> { setHasError(true); }} onScriptLoadSuccess={() => { setScriptLoaded(true); }} clientId={clientId} > ); }; export default GoogleLoginButton;