Skip to content

Commit 03e40a2

Browse files
committed
fix: pass rememberMeDays into BLC hooks, so hooks are aware what cookie time initially was going to be set and can reuse it when resume login ceremony
1 parent 3c27642 commit 03e40a2

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

adminforth/modules/restApi.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
123123
this.adminforth = adminforth;
124124
}
125125

126-
async processLoginCallbacks(adminUser: AdminUser, toReturn: { redirectTo?: string, allowedLogin:boolean, error?: string }, response: any, extra: HttpExtra) {
126+
async processLoginCallbacks(adminUser: AdminUser, toReturn: { redirectTo?: string, allowedLogin:boolean, error?: string }, response: any, extra: HttpExtra, rememberMeDays?: number) {
127127
const beforeLoginConfirmation = this.adminforth.config.auth.beforeLoginConfirmation as (BeforeLoginConfirmationFunction[] | undefined);
128128

129129
for (const hook of listify(beforeLoginConfirmation)) {
@@ -132,6 +132,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
132132
response,
133133
adminforth: this.adminforth,
134134
extra,
135+
rememberMeDays
135136
});
136137

137138
if (resp?.body?.redirectTo || resp?.error) {
@@ -197,10 +198,16 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
197198
pk: userRecord[userResource.columns.find((col) => col.primaryKey).name],
198199
username,
199200
};
200-
await this.processLoginCallbacks(adminUser, toReturn, response, { body, headers, query, cookies, requestUrl });
201+
202+
const expireInDays = rememberMe ? this.adminforth.config.auth.rememberMeDays || 30 : 1;
203+
204+
205+
await this.processLoginCallbacks(adminUser, toReturn, response, {
206+
body, headers, query, cookies, requestUrl,
207+
}, expireInDays);
201208

202209
if (toReturn.allowedLogin) {
203-
const expireInDays = rememberMe && this.adminforth.config.auth.rememberMeDays;
210+
204211
this.adminforth.auth.setAuthCookie({
205212
expireInDays,
206213
response,

adminforth/types/Back.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ export type BeforeLoginConfirmationFunction = (params?: {
603603
response: IAdminForthHttpResponse,
604604
adminforth: IAdminForth,
605605
extra?: HttpExtra,
606+
rememberMeDays?: number,
606607
}) => Promise<{
607608
error?: string,
608609
body: {

0 commit comments

Comments
 (0)