diff --git a/app/layout.tsx b/app/layout.tsx index e3cfa45..fa48b55 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -81,13 +81,8 @@ export default function RootLayout({ y.parentNode.insertBefore(t, y); })(window, document, "clarity", "script", "l869naiex9");`} + {/* google一键登录 */} - {/* */}
{children} diff --git a/components/GoogleSignIn.tsx b/components/GoogleSignIn.tsx index 697e400..0e9ac1e 100644 --- a/components/GoogleSignIn.tsx +++ b/components/GoogleSignIn.tsx @@ -1,38 +1,39 @@ -// import React, { useEffect } from "react"; -import { createClient } from "@/utils/supabase/server"; -import { cookies } from "next/headers"; +"use client"; +import React, { useEffect } from "react"; +//supabase +import { createClient } from "@/utils/supabase/client"; const GoogleSignIn = () => { - const cookieStore = cookies(); - const supabase = createClient(cookieStore); + 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); - // } else { - // initGoogleSignIn(); - // } - // }, []); + 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); + } else { + initGoogleSignIn(); + } + }, []); // 初始化Google登录 - // const initGoogleSignIn = () => { - // window.google.accounts.id.initialize({ - // client_id: ".apps.googleusercontent.com", // 替换为你的客户端ID - // callback: handleSignInWithGoogle, - // auto_select: true, // 根据需要设置 - // itp_support: true, - // }); - // window.google.accounts.id.renderButton( - // document.getElementById("g_id_signin"), - // { theme: "outline", size: "large" } - // ); - // }; + const initGoogleSignIn = () => { + window.google.accounts.id.initialize({ + client_id: + "646783243018-m2n9qfo12k70debpmkesevt5j2hi2itb.apps.googleusercontent.com", // 替换为你的客户端ID + callback: handleSignInWithGoogle, + auto_select: true, // 根据需要设置 + itp_support: true, + }); + window.google.accounts.id.renderButton( + document.getElementById("g_id_signin"), + { theme: "outline", size: "large" } + ); + }; // 处理登录响应 const handleSignInWithGoogle = async (response) => {