Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How can I allow only specific users to click a button?

Issue

I need to restrict a special admin action to specific users, but I'm not sure how to do it. What is the best solution?

Resolution

The best way to restrict special admin actions to specific users is to use Granular Access Control, a feature available in the Appsmith Business Edition. With this feature, you can control and restrict access to different entities and achieve fine-grained access control. However, if you do not have access to this edition, you can still achieve this by hiding or disabling the button based on the user's email. This can be done with Role-Based Access Control (RBAC), which allows for complete control over permissions and access.

Here's an example code snippet to hide the button for all users except for a specific email address:

const userEmail = appsmith.getCurrentEditor()?.datasource?.name;

if (userEmail !== "specificuser@email.com") {
appsmith.ui.hideComponentById("admin-button");
}

This code uses the appsmith.ui.hideComponentById() function to hide the button with the ID "admin-button" if the user's email is not equal to "specificuser@email.com".