Skip to content

Commit 403ac62

Browse files
committed
feat: add getCustomCookie method
1 parent 7f42c75 commit 403ac62

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

adminforth/auth.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ class AdminForthAuth implements IAdminForthAuth {
107107
httpOnly ? ' HttpOnly;' : ''
108108
} SameSite=Strict; Expires=${new Date(Date.now() + expiry).toUTCString() } `);
109109
}
110+
111+
getCustomCookie({ cookies, name }: {
112+
cookies: {key: string, value: string}[], name: string
113+
}): string | null {
114+
const brandSlug = this.adminforth.config.customization.brandNameSlug;
115+
return cookies.find((cookie) => cookie.key === `adminforth_${brandSlug}_${name}`)?.value || null;
116+
}
110117

111118
issueJWT(payload: Object, type: string, expiresIn: string = '24h'): string {
112119
// read ADMINFORH_SECRET from environment if not drop error

adminforth/types/Back.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ export interface IAdminForthAuth {
306306

307307
removeCustomCookie({response, name}: {response: any, name: string}): void;
308308

309+
setCustomCookie({response, payload}: {response: any, payload: {name: string, value: string, expiry: number, httpOnly: boolean}}): void;
310+
311+
getCustomCookie({cookies, name}: {cookies: {key: string, value: string}[], name: string}): string | null;
312+
309313
setAuthCookie({expireInDays, response, username, pk,}: {expireInDays?: number, response: any, username: string, pk: string}): void;
310314

311315
removeAuthCookie(response: any): void;

0 commit comments

Comments
 (0)