diff --git a/chatdesk-ui/app/[locale]/layout.tsx b/chatdesk-ui/app/[locale]/layout.tsx index ca87dbd..03d775f 100644 --- a/chatdesk-ui/app/[locale]/layout.tsx +++ b/chatdesk-ui/app/[locale]/layout.tsx @@ -124,7 +124,7 @@ export default async function RootLayout({ console.log("==========>获取到有效的 Supabase URL: ", supabaseUrl); } catch (error) { console.error("Supabase URL 获取失败:", error); - return
获取 Supabase 配置失败,请稍后再试。
; // 出现错误时返回一个友好的提示 + return
Failed to fetch Supabase configuration, please try again later.
; // 出现错误时返回一个友好的提示 } // const supabase = createServerClient( diff --git a/chatdesk-ui/app/[locale]/login/page.tsx b/chatdesk-ui/app/[locale]/login/page.tsx index 0b42bbf..07402ca 100644 --- a/chatdesk-ui/app/[locale]/login/page.tsx +++ b/chatdesk-ui/app/[locale]/login/page.tsx @@ -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`); } diff --git a/chatdesk-ui/app/api/clearCookies/route.js b/chatdesk-ui/app/api/clearCookies/route.js new file mode 100644 index 0000000..174c6cd --- /dev/null +++ b/chatdesk-ui/app/api/clearCookies/route.js @@ -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 }); +}