diff --git a/chatdesk-ui/app/api/clearCookies/route.js b/chatdesk-ui/app/api/clearCookies/route.js index a6404ed..5768113 100644 --- a/chatdesk-ui/app/api/clearCookies/route.js +++ b/chatdesk-ui/app/api/clearCookies/route.js @@ -1,33 +1,48 @@ -import { cookies, headers } from "next/headers"; +// import { cookies, headers } from "next/headers"; -export async function POST() { - const cookieStore = cookies(); - const allCookies = cookieStore.getAll(); +// export async function POST() { +// const cookieStore = cookies(); +// const allCookies = cookieStore.getAll(); - console.log("Clearing the following cookies:"); +// console.log("Clearing the following cookies:"); - // 获取当前请求的 host(服务器端) - const hostHeader = headers().get("host"); - const currentHost = hostHeader || "localhost"; // 如果没有 host 信息,使用 "localhost" +// // 获取当前请求的 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}`); - 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); - } - }); +// // Loop through all cookies and clear them +// allCookies.forEach(({ name }) => { +// 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 }); +// return new Response("Cookies cleared successfully", { status: 200 }); +// } + + + +export async function POST(req, res) { + try { + // 模拟清除所有 cookies 的操作 + console.log("Clearing all cookies..."); + + // 返回一个成功的响应 + return res.status(200).json({ message: "Cookies cleared successfully" }); + } catch (error) { + console.error("Error clearing cookies:", error); + return res.status(500).json({ error: "Failed to clear cookies" }); + } }