Skip to Main Content
Builder.io Ideas
Categories Account
Created by Alex Bridgeman
Created on Nov 5, 2024

Target user role in validation hook

For the purpose of restricting certain fields in a data model from being edited by any user, I should be able to target the current user's role in a validation hook.

Something like

 async function run() {
if (context.user.role != 'admin') {
return {
level: 'error',
message: 'only users with admin access can edit this field'
}
}
}
return run();
  • Attach files
  • Madison Dickson
    Reply
    |
    Nov 6, 2024

    Assuming this user role context was added, this could also be accomplished with an "isDisabled" option for inputs, which could let you return a truthy/falsey statement.

    Disabled state for inputs could be used for other purposes too, like read-only values that have inputs dynamically set elsewhere.