- Add Discord button to admin GitHub panel and user menu - Sync all 13 translation files to 1434 keys with native translations - Fix duplicate keys in Polish translation (pl.ts) - Fix iOS login race condition: sameSite strict→lax, loadUser sequence counter - Fix trip copy route: add missing db, Trip, TRIP_SELECT imports
23 lines
671 B
TypeScript
23 lines
671 B
TypeScript
import { Response } from 'express';
|
|
|
|
const COOKIE_NAME = 'trek_session';
|
|
|
|
export function cookieOptions(clear = false) {
|
|
const secure = process.env.COOKIE_SECURE !== 'false' && (process.env.NODE_ENV === 'production' || process.env.FORCE_HTTPS === 'true');
|
|
return {
|
|
httpOnly: true,
|
|
secure,
|
|
sameSite: 'lax' as const,
|
|
path: '/',
|
|
...(clear ? {} : { maxAge: 24 * 60 * 60 * 1000 }), // 24h — matches JWT expiry
|
|
};
|
|
}
|
|
|
|
export function setAuthCookie(res: Response, token: string): void {
|
|
res.cookie(COOKIE_NAME, token, cookieOptions());
|
|
}
|
|
|
|
export function clearAuthCookie(res: Response): void {
|
|
res.clearCookie(COOKIE_NAME, cookieOptions(true));
|
|
}
|