This commit is contained in:
hailin 2025-05-21 18:02:43 +08:00
parent ac967b2992
commit 80fa6fba00
2 changed files with 20 additions and 15 deletions

View File

@ -1,4 +1,4 @@
import { cookies } from "next/headers"; import { cookies, headers } from "next/headers";
export async function POST() { export async function POST() {
const cookieStore = cookies(); const cookieStore = cookies();
@ -6,12 +6,14 @@ export async function POST() {
console.log("Clearing the following cookies:"); console.log("Clearing the following cookies:");
// 获取当前域名 // 获取当前请求的 host服务器端
const currentHost = typeof window !== "undefined" ? window.location.hostname : "localhost"; // 在浏览器环境下获取 host const hostHeader = headers().get("host");
const currentHost = hostHeader || "localhost"; // 如果没有 host 信息,使用 "localhost"
// Loop through all cookies and clear them // Loop through all cookies and clear them
allCookies.forEach(({ name }) => { allCookies.forEach(({ name }) => {
console.log(`............Clearing cookie: ${name}`); // Log the cookie name being cleared console.log(`............Clearing cookie: ${name}`);
try {
cookieStore.set({ cookieStore.set({
name, name,
value: "", value: "",
@ -20,8 +22,11 @@ export async function POST() {
httpOnly: true, httpOnly: true,
secure: true, secure: true,
sameSite: "lax", sameSite: "lax",
domain: currentHost, // Ensure we are clearing the cookies for the current domain 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 });

View File

@ -10,7 +10,7 @@
let _env: Record<string, string> | null = null let _env: Record<string, string> | null = null
export function getRuntimeEnv(key: string): string | undefined { 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 (typeof window !== "undefined") {
if (!_env && typeof window.RUNTIME_ENV !== "undefined") { if (!_env && typeof window.RUNTIME_ENV !== "undefined") {