diff --git a/components/AuthButton.tsx b/components/AuthButton.tsx index 4a8091d..26bfbb6 100644 --- a/components/AuthButton.tsx +++ b/components/AuthButton.tsx @@ -14,7 +14,7 @@ export default async function AuthButton() { } = await supabase.auth.getUser(); //profiles表 插入用户信息 await insertUserProfile(data, supabase); - console.log("1111 in AuthButton user:", user); + // console.log("1111 in AuthButton user:", user); const signOut = async () => { "use server"; diff --git a/components/GoogleSignIn.tsx b/components/GoogleSignIn.tsx index 0e9ac1e..ed51b6f 100644 --- a/components/GoogleSignIn.tsx +++ b/components/GoogleSignIn.tsx @@ -5,18 +5,25 @@ import { createClient } from "@/utils/supabase/client"; const GoogleSignIn = () => { const supabase = createClient(); + // 加载Google身份验证库并初始化 useEffect(() => { - // 确保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); + // 检查用户是否已经登录 + const session = supabase.auth.getSession(); + if (session) { + console.log("用户已登录", session); } else { - initGoogleSignIn(); + // 确保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(); + } } }, []);