refactor: standardize session cookie configuration

Centralize cookie security options to dynamically detect HTTPS, ensure secure transport, and update client-side auth handlers to use explicit credential inclusion for cookie-based sessions.
This commit is contained in:
Team Dark Devil committed 2026-11-16 22:12:48 +06:00
1 parent fde2c86b1e
commit b42029f67d
8 files changed
+80 -53

No files matched your search

+32
View File
@@ -71,3 +71,35 @@ export async function verifyAdminSessionToken(token: string, secret: string) {
return false;
}
}
export function getSessionCookieOptions(request: Request, maxAge: number) {
const forwardedProto = request.headers
.get("x-forwarded-proto")
?.split(",")[0]
?.trim()
.toLowerCase();
const originHeader = request.headers.get("origin")?.toLowerCase() ?? "";
const isHttps =
forwardedProto === "https" ||
originHeader.startsWith("https://") ||
request.url.startsWith("https://");
if (isHttps) {
return {
httpOnly: true,
secure: true,
sameSite: "none" as const,
partitioned: true,
path: "/",
maxAge,
};
}
return {
httpOnly: true,
secure: false,
sameSite: "lax" as const,
path: "/",
maxAge,
};
}