This commit is contained in:
hailin 2025-05-21 17:45:58 +08:00
parent f5b9084468
commit ac967b2992
4 changed files with 14 additions and 19 deletions

View File

@ -26,8 +26,6 @@ export default async function Login({
searchParams: { message: string; email?: string }; searchParams: { message: string; email?: string };
params: { locale: string }; params: { locale: string };
}) { }) {
const cookieStore = cookies()
const localeString = locale; const localeString = locale;
const { t, resources } = await initTranslations(localeString, ['translation']); const { t, resources } = await initTranslations(localeString, ['translation']);
@ -35,7 +33,7 @@ export default async function Login({
const session = (await supabase.auth.getSession()).data.session const session = (await supabase.auth.getSession()).data.session
console.log("[login page]Login session:", session) console.log("[login page]Login session============================>", session)
if (session) { if (session) {
const { data: homeWorkspace, error } = await supabase const { data: homeWorkspace, error } = await supabase
@ -47,10 +45,8 @@ export default async function Login({
if (!homeWorkspace) { if (!homeWorkspace) {
// 获取 host 值,根据环境不同决定获取方式 // 获取 host 值,根据环境不同决定获取方式
let hosturl: string | undefined; let hosturl: string | undefined;
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
// 客户端环境下,使用 window.location.host // 客户端环境下,使用 window.location.host
console.log("客户端环境:使用 window.location.host 获取 host"); console.log("客户端环境:使用 window.location.host 获取 host");
@ -66,7 +62,6 @@ export default async function Login({
hosturl = process.env.SUPABASE_URL; hosturl = process.env.SUPABASE_URL;
} }
} }
console.log("最终的 hosturl 值:", hosturl); console.log("最终的 hosturl 值:", hosturl);
if (hosturl) { if (hosturl) {
await fetch(`${hosturl}/api/clearcookies`, { await fetch(`${hosturl}/api/clearcookies`, {
@ -76,7 +71,7 @@ export default async function Login({
console.error("Host URL is not available"); console.error("Host URL is not available");
} }
return redirect(`/${localeString}/login?message=sessionExpired`); return redirect(`/${localeString}/login`);
} }
return redirect(`/${localeString}/${homeWorkspace.id}/chat`); return redirect(`/${localeString}/${homeWorkspace.id}/chat`);

View File

@ -1,12 +1,17 @@
// app/api/clearCookies/route.js
import { cookies } from "next/headers"; import { cookies } from "next/headers";
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:");
// 获取当前域名
const currentHost = typeof window !== "undefined" ? window.location.hostname : "localhost"; // 在浏览器环境下获取 host
// 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
cookieStore.set({ cookieStore.set({
name, name,
value: "", value: "",
@ -15,6 +20,7 @@ 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
}); });
}); });

View File

@ -40,8 +40,6 @@ export const GlobalState: FC<GlobalStateProps> = ({ children }) => {
const router = useRouter() const router = useRouter()
const pathname = usePathname() // 获取当前路径 const pathname = usePathname() // 获取当前路径
const pathSegments = pathname.split("/").filter(Boolean) const pathSegments = pathname.split("/").filter(Boolean)
const locales = i18nConfig.locales const locales = i18nConfig.locales
@ -56,10 +54,6 @@ export const GlobalState: FC<GlobalStateProps> = ({ children }) => {
} }
const homePath = locale === defaultLocale ? "/" : `/${locale}` const homePath = locale === defaultLocale ? "/" : `/${locale}`
// PROFILE STORE // PROFILE STORE
const [profile, setProfile] = useState<Tables<"profiles"> | null>(null) const [profile, setProfile] = useState<Tables<"profiles"> | null>(null)

View File

@ -10,26 +10,26 @@
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("Checking env for key:", key) console.log("============>>Getting Supabase API call URL:", key)
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
if (!_env && typeof window.RUNTIME_ENV !== "undefined") { if (!_env && typeof window.RUNTIME_ENV !== "undefined") {
_env = window.RUNTIME_ENV _env = window.RUNTIME_ENV
console.log("Updated _env from window.RUNTIME_ENV:", _env) console.log("[browser-side] Retrieved API endpoint from window.RUNTIME_ENV:", _env);
} }
if (_env) { if (_env) {
console.log("Returning cached _env:", _env) console.log("[browser-side]Returning cached API from _env:", _env)
return _env[key] return _env[key]
} }
console.log("No window.RUNTIME_ENV found in browser") console.log("[browser-side]No window.RUNTIME_ENV found in browser")
return undefined return undefined
} }
// 服务端始终动态读取 process.env // 服务端始终动态读取 process.env
const val = process.env[key] const val = process.env[key]
console.log("Falling back to process.env for key:", key, "value:", val) console.log("[server-side] Falling back to process.env for key:", key, "value:", val)
return val return val
} }