Skip to content

Commit b3f13f7

Browse files
committed
fix: prevent users from changing their own role during updates
1 parent 9cfc2a8 commit b3f13f7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ export default {
9393
}
9494
},
9595
edit: {
96-
beforeSave: async ({ updates, adminUser, resource }: { updates: any, adminUser: AdminUser, resource: AdminForthResource }) => {
96+
beforeSave: async ({ oldRecord, updates, adminUser, resource }: { oldRecord: any, updates: any, adminUser: AdminUser, resource: AdminForthResource }) => {
9797
console.log('Updating user', updates);
98+
if (oldRecord.id === adminUser.dbUser.id && updates.role) {
99+
return { ok: false, error: 'You cannot change your own role' };
100+
}
98101
if (updates.password) {
99102
updates.password_hash = await AdminForth.Utils.generatePasswordHash(updates.password);
100103
}

0 commit comments

Comments
 (0)