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() {
|
export async function POST() {
|
||||||
const cookieStore = cookies();
|
const cookieStore = cookies();
|
||||||
|
|
@ -6,22 +6,27 @@ 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}`);
|
||||||
cookieStore.set({
|
try {
|
||||||
name,
|
cookieStore.set({
|
||||||
value: "",
|
name,
|
||||||
path: "/",
|
value: "",
|
||||||
maxAge: 0,
|
path: "/",
|
||||||
httpOnly: true,
|
maxAge: 0,
|
||||||
secure: true,
|
httpOnly: true,
|
||||||
sameSite: "lax",
|
secure: true,
|
||||||
domain: currentHost, // Ensure we are clearing the cookies for the current domain
|
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 });
|
||||||
|
|
|
||||||
|
|
@ -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") {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue