This commit is contained in:
hailin 2025-05-22 19:37:20 +08:00
parent 6748d9dde6
commit 16abb64d3c
4 changed files with 52 additions and 48 deletions

View File

@ -136,7 +136,6 @@ export default async function Login({
const signUp = async (formData: FormData) => { const signUp = async (formData: FormData) => {
"use server" "use server"
const email = formData.get("email") as string const email = formData.get("email") as string
const password = formData.get("password") as string const password = formData.get("password") as string
@ -165,8 +164,6 @@ export default async function Login({
} }
} }
//const cookieStore = cookies()
//const supabase = createClient(cookieStore)
const supabase = getSupabaseServerClient() const supabase = getSupabaseServerClient()
const { error } = await supabase.auth.signUp({ const { error } = await supabase.auth.signUp({
email, email,

View File

@ -54,18 +54,10 @@ export default function SetupPage() {
if (locales.includes(segment)) { if (locales.includes(segment)) {
locale = segment locale = segment
} }
// /zh ok
//const homePath = locale === defaultLocale ? "/" : `/${locale}`
// en ok
//const homePath = locale === defaultLocale ? "" : `/${locale}`
const getLocalizedPath = (subPath: string) => const getLocalizedPath = (subPath: string) =>
locale === defaultLocale ? `/${subPath}` : `/${locale}/${subPath}` locale === defaultLocale ? `/${subPath}` : `/${locale}/${subPath}`
// // 提取当前路径中的 locale 部分
// const locale = pathname.split("/")[1] || "en" // 获取路径中的 locale 部分,如果没有则默认为 "en"
const { t } = useTranslation() const { t } = useTranslation()
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)

View File

@ -1,57 +1,72 @@
import { cookies, headers } from "next/headers"; // import { cookies, headers } from "next/headers";
import { NextResponse } from 'next/server'; // import { NextResponse } from 'next/server';
// export async function POST() {
// const cookieStore = cookies();
// const allCookies = cookieStore.getAll();
// console.log("Clearing the following cookies:");
// // 获取当前请求的 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);
// }
// });
// // Return success response using NextResponse
// return NextResponse.json({ message: "Cookies cleared successfully" }, { status: 200 });
// }
import { cookies } from "next/headers";
import { NextResponse } from "next/server";
export async function POST() { export async function POST() {
const cookieStore = cookies(); const cookieStore = cookies();
const allCookies = cookieStore.getAll(); const allCookies = cookieStore.getAll();
console.log("Clearing the following cookies:"); console.log("🔍 Clearing the following cookies:");
allCookies.forEach(({ name }) => console.log(`- ${name}`));
// 获取当前请求的 host服务器端 const response = NextResponse.json(
const hostHeader = headers().get("host"); { message: "Cookies cleared successfully" },
const currentHost = hostHeader || "localhost"; // 如果没有 host 信息,使用 "localhost" { status: 200 }
);
// Loop through all cookies and clear them // Clear each cookie by setting an expired value
allCookies.forEach(({ name }) => { allCookies.forEach(({ name }) => {
console.log(`............Clearing cookie: ${name}`);
try { try {
cookieStore.set({ response.cookies.set({
name, name,
value: "", value: "",
path: "/", path: "/",
maxAge: 0, maxAge: 0,
httpOnly: true, httpOnly: true,
secure: true, secure: process.env.NODE_ENV === "production", // ← 自动判断环境
sameSite: "lax", sameSite: "lax",
domain: currentHost, // 使用服务器端获取的 host // No domain — will auto match current domain
}); });
} catch (error) { } catch (error) {
console.error(`Error clearing cookie ${name}:`, error); console.error(`Error clearing cookie ${name}:`, error);
} }
}); });
// Return success response using NextResponse return response;
return NextResponse.json({ message: "Cookies cleared successfully" }, { status: 200 });
} }
// import { NextResponse } from 'next/server';
// export async function POST(req) {
// try {
// console.log("Clearing cookies...");
// // Perform cookie clearing logic here
// // Return success response using NextResponse
// return NextResponse.json({ message: "Cookies cleared successfully" }, { status: 200 });
// } catch (error) {
// console.error("Error occurred while clearing cookies:", error);
// // Return error response
// return NextResponse.json({ error: "Internal server error" }, { status: 500 });
// }
// }

View File

@ -61,7 +61,7 @@ export function getRuntimeEnv(key: string): string | undefined {
return _env[key] return _env[key]
} }
console.log("[browser-side] No window.RUNTIME_ENV found in browser") console.log("[browser-side] No window.RUNTIME_ENV found in browser, _env=", _env)
let retries = 0 let retries = 0
// 定义一个同步延时重试的函数 // 定义一个同步延时重试的函数