Files
trackevery-day/lib/auth/cookies.ts
Felix Schulze 5bb861d881
All checks were successful
Lint / Lint and Check (push) Successful in 41s
env config
2025-11-15 17:23:10 +01:00

28 lines
778 B
TypeScript

import { cookies } from 'next/headers';
import '@/lib/env-config';
const TOKEN_COOKIE_NAME = 'habit-tracker-token';
const TOKEN_COOKIE_OPTIONS = {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax' as const,
maxAge: 60 * 60 * 24 * 365, // 1 year
path: '/',
};
export async function setTokenCookie(token: string) {
const cookieStore = await cookies();
cookieStore.set(TOKEN_COOKIE_NAME, token, TOKEN_COOKIE_OPTIONS);
}
export async function getTokenCookie(): Promise<string | undefined> {
const cookieStore = await cookies();
const cookie = cookieStore.get(TOKEN_COOKIE_NAME);
return cookie?.value;
}
export async function deleteTokenCookie() {
const cookieStore = await cookies();
cookieStore.delete(TOKEN_COOKIE_NAME);
}