Skip to content

Commit 02e683d

Browse files
author
yaroslav8765
committed
fix: add possibility to pass void functions to the loginPromptHTML
1 parent 51d0c0c commit 02e683d

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

adminforth/commands/createApp/templates/index.ts.hbs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export const admin = new AdminForth({
2020
if (adminforthUserExists) {
2121
return "Please use <b>adminforth</b> as username and <b>adminforth</b> as password"
2222
}
23-
return "";
2423
},
2524
},
2625
customization: {

adminforth/modules/restApi.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
210210
const resource = this.adminforth.config.resources.find((res) => res.resourceId === this.adminforth.config.auth.usersResourceId);
211211
const usernameColumn = resource.columns.find((col) => col.name === usernameField);
212212

213-
let loginPromptHTML;
214-
if(typeof this.adminforth.config.auth.loginPromptHTML === 'function') {
215-
loginPromptHTML = await this.adminforth.config.auth.loginPromptHTML();
216-
} else {
217-
loginPromptHTML = this.adminforth.config.auth.loginPromptHTML;
218-
}
213+
let loginPromptHTML = await getLoginPromptHTML(this.adminforth.config.auth.loginPromptHTML);
219214

220215
return {
221216
brandName: this.adminforth.config.customization.brandName,
@@ -234,7 +229,17 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
234229
},
235230
});
236231

237-
232+
async function getLoginPromptHTML(prompt) {
233+
if(typeof prompt === 'function') {
234+
const result = await prompt();
235+
if(result !== undefined){
236+
return result;
237+
}
238+
return "";
239+
} else {
240+
return prompt;
241+
}
242+
}
238243
server.endpoint({
239244
method: 'GET',
240245
path: '/get_base_config',
@@ -298,12 +303,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
298303

299304
const announcementBadge: AnnouncementBadgeResponse = this.adminforth.config.customization.announcementBadge?.(adminUser);
300305

301-
let loginPromptHTML;
302-
if(typeof this.adminforth.config.auth.loginPromptHTML === 'function') {
303-
loginPromptHTML = await this.adminforth.config.auth.loginPromptHTML();
304-
} else {
305-
loginPromptHTML = this.adminforth.config.auth.loginPromptHTML;
306-
}
306+
let loginPromptHTML = await getLoginPromptHTML(this.adminforth.config.auth.loginPromptHTML);
307307

308308

309309
const publicPart = {

adminforth/types/Back.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ export interface AdminForthInputConfig {
956956
/**
957957
* Any prompt to show users on login. Supports HTML.
958958
*/
959-
loginPromptHTML?: string | (() => string | Promise<string>)
959+
loginPromptHTML?: string | (() => string | void | undefined | Promise<string | void | undefined>) | undefined
960960

961961
/**
962962
* Remember me days for "Remember Me" checkbox on login page.

adminforth/types/Common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ export interface AdminForthConfigForFrontend {
10571057
loginBackgroundPosition: string,
10581058
title?: string,
10591059
demoCredentials?: string,
1060-
loginPromptHTML?: string | (() => string | Promise<string>)
1060+
loginPromptHTML?: string | (() => string | Promise<string> | void | Promise<void> | Promise<undefined>) | undefined
10611061
loginPageInjections: {
10621062
underInputs: Array<AdminForthComponentDeclaration>,
10631063
panelHeader: Array<AdminForthComponentDeclaration>,

0 commit comments

Comments
 (0)