Skip to content

Commit e1d9113

Browse files
committed
fix: Support both single function and array for beforeLoginConfirmation
1 parent 8bf8476 commit e1d9113

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

adminforth/modules/restApi.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,21 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
8484

8585
async processLoginCallbacks(adminUser: AdminUser, toReturn: { redirectTo?: string, allowedLogin:boolean, error?: string }, response: any, extra: HttpExtra) {
8686
const beforeLoginConfirmation = this.adminforth.config.auth.beforeLoginConfirmation as (BeforeLoginConfirmationFunction[] | undefined);
87-
if (beforeLoginConfirmation?.length){
88-
for (const hook of beforeLoginConfirmation) {
89-
const resp = await hook({
90-
adminUser,
91-
response,
92-
adminforth: this.adminforth,
93-
extra,
94-
});
95-
96-
if (resp?.body?.redirectTo || resp?.error) {
97-
// delete all items from toReturn and add these:
98-
toReturn.redirectTo = resp?.body?.redirectTo;
99-
toReturn.allowedLogin = resp?.body?.allowedLogin;
100-
toReturn.error = resp?.error;
101-
break;
102-
}
87+
88+
for (const hook of listify(Array.isArray(beforeLoginConfirmation) ? beforeLoginConfirmation : [beforeLoginConfirmation])) {
89+
const resp = await hook({
90+
adminUser,
91+
response,
92+
adminforth: this.adminforth,
93+
extra,
94+
});
95+
96+
if (resp?.body?.redirectTo || resp?.error) {
97+
// delete all items from toReturn and add these:
98+
toReturn.redirectTo = resp?.body?.redirectTo;
99+
toReturn.allowedLogin = resp?.body?.allowedLogin;
100+
toReturn.error = resp?.error;
101+
break;
103102
}
104103
}
105104
}

0 commit comments

Comments
 (0)