This commit is contained in:
hailin 2025-05-21 15:53:28 +08:00
parent ac568cc9fd
commit 49a5f0f1dd
3 changed files with 29 additions and 17 deletions

View File

@ -124,7 +124,7 @@ export default async function RootLayout({
console.log("==========>获取到有效的 Supabase URL: ", supabaseUrl);
} catch (error) {
console.error("Supabase URL 获取失败:", error);
return <div> Supabase </div>; // 出现错误时返回一个友好的提示
return <div>Failed to fetch Supabase configuration, please try again later.</div>; // 出现错误时返回一个友好的提示
}
// const supabase = createServerClient<Database>(

View File

@ -57,26 +57,16 @@ export default async function Login({
.eq("is_home", true)
.maybeSingle();
if (!homeWorkspace) {
// 清除当前请求的所有 cookie
const cookieStore = cookies();
const allCookies = cookieStore.getAll(); // 获取当前请求的所有 cookies
allCookies.forEach(({ name }) => {
cookieStore.set({
name,
value: "",
path: "/",
maxAge: 0,
httpOnly: true,
secure: true,
sameSite: "lax",
const clearCookies = async () => {
await fetch("/api/clearCookies", {
method: "POST",
});
});
};
if (!homeWorkspace) {
await clearCookies(); // Clear cookies if home workspace is not found
return redirect(`/${localeString}/login?message=sessionExpired`);
}
return redirect(`/${localeString}/${homeWorkspace.id}/chat`);
}

View File

@ -0,0 +1,22 @@
// app/api/clearCookies/route.js
import { cookies } from "next/headers";
export async function POST() {
const cookieStore = cookies();
const allCookies = cookieStore.getAll();
// Loop through all cookies and clear them
allCookies.forEach(({ name }) => {
cookieStore.set({
name,
value: "",
path: "/",
maxAge: 0,
httpOnly: true,
secure: true,
sameSite: "lax",
});
});
return new Response("Cookies cleared successfully", { status: 200 });
}