chore: 使用同步尝试去除onetap

This commit is contained in:
liuweiqing 2024-03-09 21:55:25 +08:00
parent b5bd878cda
commit e0426cf5fc

View File

@ -8,25 +8,34 @@ const GoogleSignIn = () => {
// 加载Google身份验证库并初始化 // 加载Google身份验证库并初始化
useEffect(() => { useEffect(() => {
// 检查用户是否已经登录 // 异步检查用户是否已经登录
const session = supabase.auth.getSession(); const checkSession = async () => {
if (session) { const session = await supabase.auth.getSession();
console.log("用户已登录", session);
} else { if (session) {
// 确保gapi脚本只被加载一次 console.log("用户已登录", session);
if (!window.gapi) {
const script = document.createElement("script");
script.src = "https://accounts.google.com/gsi/client";
script.async = true;
script.defer = true;
script.onload = initGoogleSignIn;
document.body.appendChild(script);
} else { } else {
initGoogleSignIn(); loadGoogleSignInScript();
} }
} };
checkSession();
}, []); }, []);
const loadGoogleSignInScript = () => {
// 确保gapi脚本只被加载一次
if (!window.gapi) {
const script = document.createElement("script");
script.src = "https://accounts.google.com/gsi/client";
script.async = true;
script.defer = true;
script.onload = initGoogleSignIn;
document.body.appendChild(script);
} else {
initGoogleSignIn();
}
};
// 初始化Google登录 // 初始化Google登录
const initGoogleSignIn = () => { const initGoogleSignIn = () => {
window.google.accounts.id.initialize({ window.google.accounts.id.initialize({