chore: google onetap
This commit is contained in:
parent
04a3e64e64
commit
84239677f5
|
@ -81,13 +81,8 @@ export default function RootLayout({
|
|||
y.parentNode.insertBefore(t, y);
|
||||
})(window, document, "clarity", "script", "l869naiex9");`}
|
||||
</Script>
|
||||
{/* google一键登录 */}
|
||||
<Script src="https://accounts.google.com/gsi/client" async></Script>
|
||||
{/* <Script>{`async function handleSignInWithGoogle(response) {
|
||||
const { data, error } = await supabase.auth.signInWithIdToken({
|
||||
provider: 'google',
|
||||
token: response.credential,
|
||||
})
|
||||
}`}</Script> */}
|
||||
<body className="bg-background text-foreground">
|
||||
<main className="min-h-screen flex flex-col items-center">
|
||||
{children}
|
||||
|
|
|
@ -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: "<your-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) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user