18 lines
462 B
TypeScript
18 lines
462 B
TypeScript
import type { CookieOptions } from "hono/utils/cookie";
|
|
|
|
function isLocalhost(headers: Headers): boolean {
|
|
const host = headers.get("host") || "";
|
|
return host.startsWith("localhost:") || host.startsWith("127.0.0.1:");
|
|
}
|
|
|
|
export function getSessionCookieOptions(headers: Headers): CookieOptions {
|
|
const localhost = isLocalhost(headers);
|
|
|
|
return {
|
|
httpOnly: true,
|
|
path: "/",
|
|
sameSite: localhost ? "Lax" : "None",
|
|
secure: !localhost,
|
|
};
|
|
}
|