From c929269e8e8380221e4f3f479c9aebbd64befad0 Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 22 Apr 2025 08:32:06 +0800 Subject: [PATCH] . --- app/[locale]/layout.tsx | 4 +- components/utility/profile-settings.tsx | 58 +++++++++++++++++++++---- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/app/[locale]/layout.tsx b/app/[locale]/layout.tsx index 23ffc9a..fe21f72 100644 --- a/app/[locale]/layout.tsx +++ b/app/[locale]/layout.tsx @@ -85,9 +85,9 @@ export default async function RootLayout({ // const session = (await supabase.auth.getSession()).data.session const { data, error } = await supabase.auth.getSession(); if (error) { - console.log("[layout.tsx]Session Error: ", error); + console.log("............[layout.tsx]Session Error: ", error); } else { - console.log("[layout.tsx]Session Data: ", data.session); + console.log("............[layout.tsx]Session Data: ", data.session); } const { t, resources } = await initTranslations(locale, i18nNamespaces) diff --git a/components/utility/profile-settings.tsx b/components/utility/profile-settings.tsx index 0e7d217..19708e8 100644 --- a/components/utility/profile-settings.tsx +++ b/components/utility/profile-settings.tsx @@ -131,16 +131,60 @@ export const ProfileSettings: FC = ({}) => { profile?.openrouter_api_key || "" ) - const handleSignOut = async () => { - await supabase.auth.signOut() + // const handleSignOut = async () => { + // await supabase.auth.signOut() + // // ✅ 清除 localStorage 中的语言偏好 + // if (typeof window !== "undefined") { + // localStorage.removeItem("preferred-language") + // } + + // // ✅ 清除 Cookie 中的语言偏好(设置 max-age=0 立即过期) + // document.cookie = "preferred-language=; path=/; max-age=0" + + // const pathSegments = pathname.split("/").filter(Boolean) + // const locales = i18nConfig.locales + // const defaultLocale = i18nConfig.defaultLocale + + // let locale: (typeof locales)[number] = defaultLocale + + // const segment = pathSegments[0] as (typeof locales)[number] + + // if (locales.includes(segment)) { + // locale = segment + // } + + // const homePath = locale === defaultLocale ? "/" : `/${locale}` + + // router.push(homePath) + // router.refresh() + // return + // } + + + + + const handleSignOut = async () => { + try { + // 调用 Supabase 注销 + await supabase.auth.signOut(); + } catch (error) { + console.error("Sign-out error:", error); + // 在错误发生时显示反馈或进行其他处理 + return; + } + // ✅ 清除 localStorage 中的语言偏好 if (typeof window !== "undefined") { - localStorage.removeItem("preferred-language") + localStorage.removeItem("preferred-language"); } - + // ✅ 清除 Cookie 中的语言偏好(设置 max-age=0 立即过期) - document.cookie = "preferred-language=; path=/; max-age=0" + document.cookie = "preferred-language=; path=/; max-age=0"; + + // 清除相关 cookies,例如 access_token 和 refresh_token + document.cookie = "access_token=; path=/; max-age=0"; + document.cookie = "refresh_token=; path=/; max-age=0"; const pathSegments = pathname.split("/").filter(Boolean) const locales = i18nConfig.locales @@ -153,13 +197,11 @@ export const ProfileSettings: FC = ({}) => { if (locales.includes(segment)) { locale = segment } - const homePath = locale === defaultLocale ? "/" : `/${locale}` - router.push(homePath) router.refresh() return - } + }; const handleSave = async () => { if (!profile) return