import { validateSession } from "./userAuth.js";
const COOKIE_NAME = "cross-seed-session";
const COOKIE_OPTIONS = {
    httpOnly: true,
    secure: process.env.NODE_ENV === "production", // Only set secure in production
    maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days in milliseconds (match session expiry)
    path: "/",
    sameSite: "lax",
};
export function setSessionCookie(reply, sessionId) {
    void reply.setCookie(COOKIE_NAME, sessionId, COOKIE_OPTIONS);
}
export function clearSessionCookie(reply) {
    void reply.clearCookie(COOKIE_NAME, { path: "/" });
}
export function getSessionCookie(request) {
    return request.cookies[COOKIE_NAME];
}
export async function validateAuth(request) {
    const sessionId = getSessionCookie(request);
    if (!sessionId) {
        return false;
    }
    const user = await validateSession(sessionId);
    return !!user;
}
//# sourceMappingURL=sessionCookies.js.map