diff --git a/server/dashboard/src/app/api/auth/refresh/route.ts b/server/dashboard/src/app/api/auth/refresh/route.ts index cc827c41a..0de4609d7 100644 --- a/server/dashboard/src/app/api/auth/refresh/route.ts +++ b/server/dashboard/src/app/api/auth/refresh/route.ts @@ -4,9 +4,23 @@ import { AUTH_ENDPOINTS } from "@/utils/api-endpoints"; import { getServerApiUrl } from "@/lib/server-api-url"; const COOKIE_NAME = "mem0_refresh_token"; + +function shouldUseSecureCookie() { + const dashboardUrl = process.env.DASHBOARD_URL; + if (!dashboardUrl) { + return process.env.NODE_ENV === "production"; + } + + try { + return new URL(dashboardUrl).protocol === "https:"; + } catch { + return process.env.NODE_ENV === "production"; + } +} + const COOKIE_OPTIONS = { httpOnly: true, - secure: process.env.NODE_ENV === "production", + secure: shouldUseSecureCookie(), sameSite: "lax" as const, path: "/", maxAge: 30 * 24 * 60 * 60, // 30 days