diff --git a/chatdesk-ui/app/[locale]/login/page.tsx b/chatdesk-ui/app/[locale]/login/page.tsx index 647f0f7..27619d3 100644 --- a/chatdesk-ui/app/[locale]/login/page.tsx +++ b/chatdesk-ui/app/[locale]/login/page.tsx @@ -26,8 +26,6 @@ export default async function Login({ searchParams: { message: string; email?: string }; params: { locale: string }; }) { - const cookieStore = cookies() - const localeString = locale; const { t, resources } = await initTranslations(localeString, ['translation']); @@ -35,7 +33,7 @@ export default async function Login({ const session = (await supabase.auth.getSession()).data.session - console.log("[login page]Login session:", session) + console.log("[login page]Login session============================>", session) if (session) { const { data: homeWorkspace, error } = await supabase @@ -47,10 +45,8 @@ export default async function Login({ if (!homeWorkspace) { - // 获取 host 值,根据环境不同决定获取方式 let hosturl: string | undefined; - if (typeof window !== "undefined") { // 客户端环境下,使用 window.location.host console.log("客户端环境:使用 window.location.host 获取 host"); @@ -66,7 +62,6 @@ export default async function Login({ hosturl = process.env.SUPABASE_URL; } } - console.log("最终的 hosturl 值:", hosturl); if (hosturl) { await fetch(`${hosturl}/api/clearcookies`, { @@ -76,7 +71,7 @@ export default async function Login({ console.error("Host URL is not available"); } - return redirect(`/${localeString}/login?message=sessionExpired`); + return redirect(`/${localeString}/login`); } return redirect(`/${localeString}/${homeWorkspace.id}/chat`); diff --git a/chatdesk-ui/app/api/clearCookies/route.js b/chatdesk-ui/app/api/clearCookies/route.js index 174c6cd..ff59e4f 100644 --- a/chatdesk-ui/app/api/clearCookies/route.js +++ b/chatdesk-ui/app/api/clearCookies/route.js @@ -1,12 +1,17 @@ -// app/api/clearCookies/route.js import { cookies } from "next/headers"; export async function POST() { const cookieStore = cookies(); 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 allCookies.forEach(({ name }) => { + console.log(`............Clearing cookie: ${name}`); // Log the cookie name being cleared cookieStore.set({ name, value: "", @@ -15,6 +20,7 @@ export async function POST() { httpOnly: true, secure: true, sameSite: "lax", + domain: currentHost, // Ensure we are clearing the cookies for the current domain }); }); diff --git a/chatdesk-ui/components/utility/global-state.tsx b/chatdesk-ui/components/utility/global-state.tsx index 316758f..acd4994 100644 --- a/chatdesk-ui/components/utility/global-state.tsx +++ b/chatdesk-ui/components/utility/global-state.tsx @@ -40,8 +40,6 @@ export const GlobalState: FC = ({ children }) => { const router = useRouter() - - const pathname = usePathname() // 获取当前路径 const pathSegments = pathname.split("/").filter(Boolean) const locales = i18nConfig.locales @@ -56,10 +54,6 @@ export const GlobalState: FC = ({ children }) => { } const homePath = locale === defaultLocale ? "/" : `/${locale}` - - - - // PROFILE STORE const [profile, setProfile] = useState | null>(null) diff --git a/chatdesk-ui/lib/ipconfig.ts b/chatdesk-ui/lib/ipconfig.ts index c2e4b5a..48f8c6f 100644 --- a/chatdesk-ui/lib/ipconfig.ts +++ b/chatdesk-ui/lib/ipconfig.ts @@ -10,26 +10,26 @@ let _env: Record | null = null 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 (!_env && typeof window.RUNTIME_ENV !== "undefined") { _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) { - console.log("Returning cached _env:", _env) + console.log("[browser-side]Returning cached API from _env:", _env) 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 } // 服务端始终动态读取 process.env 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 }