fix: allow dashboard refresh cookie on http deployments (#5026)
This commit is contained in:
@@ -4,9 +4,23 @@ import { AUTH_ENDPOINTS } from "@/utils/api-endpoints";
|
|||||||
import { getServerApiUrl } from "@/lib/server-api-url";
|
import { getServerApiUrl } from "@/lib/server-api-url";
|
||||||
|
|
||||||
const COOKIE_NAME = "mem0_refresh_token";
|
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 = {
|
const COOKIE_OPTIONS = {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: process.env.NODE_ENV === "production",
|
secure: shouldUseSecureCookie(),
|
||||||
sameSite: "lax" as const,
|
sameSite: "lax" as const,
|
||||||
path: "/",
|
path: "/",
|
||||||
maxAge: 30 * 24 * 60 * 60, // 30 days
|
maxAge: 30 * 24 * 60 * 60, // 30 days
|
||||||
|
|||||||
Reference in New Issue
Block a user