diff --git a/adminforth/modules/restApi.ts b/adminforth/modules/restApi.ts index 499ee606..e9a73708 100644 --- a/adminforth/modules/restApi.ts +++ b/adminforth/modules/restApi.ts @@ -250,7 +250,6 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI { const usernameColumn = userResource.columns.find((col) => col.name === usernameField); const userPk = dbUser[userResource.columns.find((col) => col.primaryKey).name]; - const userData = { [this.adminforth.config.auth.usernameField]: username, [this.adminforth.config.auth.userFullNameField]: userFullName, @@ -291,7 +290,8 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI { } const announcementBadge: AnnouncementBadgeResponse = this.adminforth.config.customization.announcementBadge?.(adminUser); - + const adminforthUserCleanupWarning: AnnouncementBadgeResponse = this.adminforth.config.customization.adminforthUserCleanupWarning?.(adminUser); + const publicPart = { brandName: this.adminforth.config.customization.brandName, usernameFieldName: usernameColumn.label, @@ -314,6 +314,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI { title: this.adminforth.config.customization.title, emptyFieldPlaceholder: this.adminforth.config.customization.emptyFieldPlaceholder, announcementBadge, + adminforthUserCleanupWarning, globalInjections: this.adminforth.config.customization.globalInjections, userFullnameField: this.adminforth.config.auth.userFullNameField, } diff --git a/adminforth/spa/src/App.vue b/adminforth/spa/src/App.vue index 2a42eec6..c5fe4b8d 100644 --- a/adminforth/spa/src/App.vue +++ b/adminforth/spa/src/App.vue @@ -165,7 +165,21 @@

- +
+
+ + + {{adminforthUserCleanupWarning.title}} + + +
+

+

+ {{ adminforthUserCleanupWarning.text }} +

+
{ + const badge = coreStore.config?.adminforthUserCleanupWarning; + if (!badge) return null; + if (process.env.NODE_ENV !== 'production' || coreStore.adminUser?.dbUser.email !== 'adminforth') return null; + return { ...badge }; +}); + diff --git a/adminforth/types/Back.ts b/adminforth/types/Back.ts index f3427ff8..4c1e1165 100644 --- a/adminforth/types/Back.ts +++ b/adminforth/types/Back.ts @@ -739,6 +739,13 @@ interface AdminForthInputConfigCustomization { * Execution is done on admin app load. */ announcementBadge?: (user: AdminUser) => AnnouncementBadgeResponse, + + /** + * Function to return custom badge in side bar for users. Can return text or html + * If function is not passed or returns null, badge will not be shown. + * Execution is done on admin app load. + */ + adminforthUserCleanupWarning?: (user: AdminUser) => AnnouncementBadgeResponse, /** * Custom panel components or array of components which will be displayed in the login form @@ -964,7 +971,6 @@ export interface AdminForthInputConfig { */ rememberMeDays?: number, - /** * Can be used to limit user access when subscribing from frontend to websocket topics. * @param topic - topic where user is trying to subscribe diff --git a/adminforth/types/Common.ts b/adminforth/types/Common.ts index 7385fc33..4ffcdde7 100644 --- a/adminforth/types/Common.ts +++ b/adminforth/types/Common.ts @@ -1058,6 +1058,7 @@ export interface AdminForthConfigForFrontend { list?: string, }, announcementBadge?: AnnouncementBadgeResponse | null, + adminforthUserCleanupWarning?: AnnouncementBadgeResponse | null, globalInjections: { userMenu: Array, header: Array, diff --git a/dev-demo/index.ts b/dev-demo/index.ts index d10c4199..d3cee0c3 100644 --- a/dev-demo/index.ts +++ b/dev-demo/index.ts @@ -176,6 +176,19 @@ export const admin = new AdminForth({ } }, + adminforthUserCleanupWarning: (adminUser: AdminUser) => { + return { + html: ` +

The default admin user adminforth is still active in production.

+

For security reasons, it's strongly recommended to create your own account and delete this default user.

+
+

This action is critical and cannot be undone.

+ `, + closable: false, + title: 'Critical Security Warning', + } + }, + // loginPageInjections: { // underInputs: '@@/login2.vue', // } @@ -506,8 +519,8 @@ admin.express.serve(app); admin.discoverDatabases().then(async () => { console.log('🅿️ Database discovered'); - if (!await admin.resource('users').get([Filters.EQ('email', 'adminforth')])) { - await admin.resource('users').create({ + if (await admin.resource('adminuser').count() === 0) { + await admin.resource('adminuser').create({ email: 'adminforth', password_hash: await AdminForth.Utils.generatePasswordHash('adminforth'), role: 'superadmin',