This commit is contained in:
parent
ac568cc9fd
commit
49a5f0f1dd
|
|
@ -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>(
|
||||
|
|
|
|||
|
|
@ -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`);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
}
|
||||
Loading…
Reference in New Issue