This commit is contained in:
hailin 2025-04-22 08:32:06 +08:00
parent ba2c8b985f
commit c929269e8e
2 changed files with 52 additions and 10 deletions

View File

@ -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)

View File

@ -131,16 +131,60 @@ export const ProfileSettings: FC<ProfileSettingsProps> = ({}) => {
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<ProfileSettingsProps> = ({}) => {
if (locales.includes(segment)) {
locale = segment
}
const homePath = locale === defaultLocale ? "/" : `/${locale}`
router.push(homePath)
router.refresh()
return
}
};
const handleSave = async () => {
if (!profile) return