import type { Response } from "express";
import { env } from "./env.js";

const NOME_COOKIE = "biblioteca_sessao";

export function definirCookieSessao(res: Response, token: string) {
  res.cookie(NOME_COOKIE, token, {
    httpOnly: true,
    secure: env.nodeEnv === "production",
    sameSite: "lax",
    maxAge: 30 * 24 * 60 * 60 * 1000,
    path: "/",
  });
}

export function limparCookieSessao(res: Response) {
  res.clearCookie(NOME_COOKIE, { path: "/" });
}
