Skip to content

Commit 5b4aeef

Browse files
committed
normalize beforeLoginConfirmation to support both single function and array formats
1 parent e1d9113 commit 5b4aeef

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

adminforth/modules/configValidator.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,16 @@ export default class ConfigValidator implements IConfigValidator {
942942
throw new Error(`Resource with id "${newConfig.auth.usersResourceId}" not found. ${similar ? `Did you mean "${similar}"?` : ''}`);
943943
}
944944

945-
if (!newConfig.auth.beforeLoginConfirmation) {
946-
newConfig.auth.beforeLoginConfirmation = [];
945+
// normalize beforeLoginConfirmation hooks
946+
const blc = this.inputConfig.auth.beforeLoginConfirmation;
947+
if (!Array.isArray(blc)) {
948+
if (blc) {
949+
newConfig.auth.beforeLoginConfirmation = [blc];
950+
} else {
951+
newConfig.auth.beforeLoginConfirmation = [];
952+
}
953+
} else {
954+
newConfig.auth.beforeLoginConfirmation = blc;
947955
}
948956
}
949957

adminforth/modules/restApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
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);
8787

88-
for (const hook of listify(Array.isArray(beforeLoginConfirmation) ? beforeLoginConfirmation : [beforeLoginConfirmation])) {
88+
for (const hook of listify(beforeLoginConfirmation)) {
8989
const resp = await hook({
9090
adminUser,
9191
response,

0 commit comments

Comments
 (0)