"use server";

import { cookies } from "next/headers";

export const setAuthTokenToCookie = async (token: string): Promise<void> => {
  const cookieStore = await cookies();
  cookieStore.set("accessToken", token, {
    httpOnly: true,
    secure: process.env.NODE_ENV === "production",
    path: "/",
    sameSite: "lax",
    maxAge: 60 * 60 * 24 * 365,
  });
};

export const getAuthTokenFromCookie = async (): Promise<string | undefined> => {
  const cookieStore = await cookies();
  return cookieStore.get("accessToken")?.value;
};
