From 80fa6fba004c7c4bf8314f375e51b89cc6d2b816 Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 21 May 2025 18:02:43 +0800 Subject: [PATCH] . --- chatdesk-ui/app/api/clearCookies/route.js | 33 +++++++++++++---------- chatdesk-ui/lib/ipconfig.ts | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/chatdesk-ui/app/api/clearCookies/route.js b/chatdesk-ui/app/api/clearCookies/route.js index ff59e4f..a6404ed 100644 --- a/chatdesk-ui/app/api/clearCookies/route.js +++ b/chatdesk-ui/app/api/clearCookies/route.js @@ -1,4 +1,4 @@ -import { cookies } from "next/headers"; +import { cookies, headers } from "next/headers"; export async function POST() { const cookieStore = cookies(); @@ -6,22 +6,27 @@ export async function POST() { console.log("Clearing the following cookies:"); - // 获取当前域名 - const currentHost = typeof window !== "undefined" ? window.location.hostname : "localhost"; // 在浏览器环境下获取 host + // 获取当前请求的 host(服务器端) + const hostHeader = headers().get("host"); + const currentHost = hostHeader || "localhost"; // 如果没有 host 信息,使用 "localhost" // Loop through all cookies and clear them allCookies.forEach(({ name }) => { - console.log(`............Clearing cookie: ${name}`); // Log the cookie name being cleared - cookieStore.set({ - name, - value: "", - path: "/", - maxAge: 0, - httpOnly: true, - secure: true, - sameSite: "lax", - domain: currentHost, // Ensure we are clearing the cookies for the current domain - }); + console.log(`............Clearing cookie: ${name}`); + try { + cookieStore.set({ + name, + value: "", + path: "/", + maxAge: 0, + httpOnly: true, + secure: true, + sameSite: "lax", + domain: currentHost, // 使用服务器端获取的 host + }); + } catch (error) { + console.error(`Error clearing cookie ${name}:`, error); + } }); return new Response("Cookies cleared successfully", { status: 200 }); diff --git a/chatdesk-ui/lib/ipconfig.ts b/chatdesk-ui/lib/ipconfig.ts index 48f8c6f..9862ffc 100644 --- a/chatdesk-ui/lib/ipconfig.ts +++ b/chatdesk-ui/lib/ipconfig.ts @@ -10,7 +10,7 @@ let _env: Record | null = null export function getRuntimeEnv(key: string): string | undefined { - console.log("============>>Getting Supabase API call URL:", key) + console.log("============>>Getting Supabase API call URL.") if (typeof window !== "undefined") { if (!_env && typeof window.RUNTIME_ENV !== "undefined") {