Skip to content

Commit 62d130e

Browse files
committed
1 parent f5a4ba8 commit 62d130e

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

adminforth/auth.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ getClientIp(headers: object) {
106106
}
107107

108108
setCustomCookie({ response, payload }: {
109-
response: any, payload: { name: string, value: string, expiry?: number | undefined, expirySeconds: number | undefined, httpOnly: boolean }
109+
response: any, payload: { name: string, value: string, expiry?: number | undefined, expirySeconds: number | undefined, httpOnly: boolean, sessionBased?: boolean | undefined }
110110
}) {
111-
const {name, value, expiry, httpOnly, expirySeconds } = payload;
111+
const {name, value, expiry, httpOnly, expirySeconds, sessionBased } = payload;
112112

113113
let expiryMs = 24 * 60 * 60 * 1000; // default 1 day
114114
if (expirySeconds !== undefined) {
@@ -117,11 +117,14 @@ getClientIp(headers: object) {
117117
afLogger.warn(`setCustomCookie: expiry(in ms) is deprecated, use expirySeconds instead (seconds), traceback: ${new Error().stack}`);
118118
expiryMs = expiry;
119119
}
120-
121120
const brandSlug = this.adminforth.config.customization.brandNameSlug;
122-
response.setHeader('Set-Cookie', `adminforth_${brandSlug}_${name}=${value}; Path=${this.adminforth.config.baseUrl || '/'};${
123-
httpOnly ? ' HttpOnly;' : ''
124-
} SameSite=Strict; Expires=${new Date(Date.now() + expiryMs).toUTCString() } `);
121+
response.setHeader('Set-Cookie',
122+
`adminforth_${brandSlug}_${name}=${value}; Path=${this.adminforth.config.baseUrl || '/'};${
123+
httpOnly ? ' HttpOnly;' : ''
124+
}SameSite=Strict;${
125+
sessionBased ? '' : `Expires=${new Date(Date.now() + expiryMs).toUTCString() }`
126+
}`
127+
);
125128
}
126129

127130
getCustomCookie({ cookies, name }: {

0 commit comments

Comments
 (0)