This commit is contained in:
parent
ac967b2992
commit
80fa6fba00
|
|
@ -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 });
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
let _env: Record<string, string> | 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") {
|
||||
|
|
|
|||
Loading…
Reference in New Issue