From 4caed997dfc4f1da204a4a323da66a6b1c9cf242 Mon Sep 17 00:00:00 2001 From: Ivan Borshchov Date: Mon, 6 Oct 2025 12:12:39 +0000 Subject: [PATCH] fix: update setCustomCookie to use expirySeconds and deprecate expiry (fallback still) --- adminforth/auth.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/adminforth/auth.ts b/adminforth/auth.ts index 342e0405..ad518c50 100644 --- a/adminforth/auth.ts +++ b/adminforth/auth.ts @@ -99,13 +99,22 @@ class AdminForthAuth implements IAdminForthAuth { } setCustomCookie({ response, payload }: { - response: any, payload: {name: string, value: string, expiry: number, httpOnly: boolean} + response: any, payload: { name: string, value: string, expiry: number | undefined, expirySeconds: number | undefined, httpOnly: boolean } }) { - const {name, value, expiry, httpOnly} = payload; + const {name, value, expiry, httpOnly, expirySeconds } = payload; + + let expiryMs = 24 * 60 * 60 * 1000; // default 1 day + if (expirySeconds !== undefined) { + expiryMs = expirySeconds * 1000; + } else if (expiry !== undefined) { + console.warn('setCustomCookie: expiry(in ms) is deprecated, use expirySeconds instead (seconds), traceback:', new Error().stack); + expiryMs = expiry; + } + const brandSlug = this.adminforth.config.customization.brandNameSlug; response.setHeader('Set-Cookie', `adminforth_${brandSlug}_${name}=${value}; Path=${this.adminforth.config.baseUrl || '/'};${ httpOnly ? ' HttpOnly;' : '' - } SameSite=Strict; Expires=${new Date(Date.now() + expiry).toUTCString() } `); + } SameSite=Strict; Expires=${new Date(Date.now() + expiryMs).toUTCString() } `); } getCustomCookie({ cookies, name }: {