Check Permissions

Import Salesforce permissions from the @salesforce/userPermission and @salesforce/customPermission scoped modules. Customize a component’s behavior based on the permissions of the context user.

See the miscPermissionBasedUI recipe in the lwc-recipes repo.

To check whether a user has a permission, import a static reference to the permission and evaluate whether it’s true or undefined.

Checking for a custom permission has a similar syntax. Don't use a namespace with the permission name if you reference a custom permission from a component in the same namespace as the permission, including the default namespace.

If the custom permission was installed from a managed package, prepend the namespace followed by __ to the permission name.

The name of the static reference is your choice. We chose the format has{Permission} to indicate that the reference contains a boolean.

This sample checks whether the current user has the ViewSetup standard permission.

If the user has the permission, !hasViewSetup results in the disabled attribute evaluating to false, so the button is not disabled.

This sample checks whether the current user has the ViewReport custom permission installed from a managed package with the acme namespace.

If the user has the permission, the component displays the expense-report component .

Replace any cases where a parent Aura component references permissions dynamically with a static reference in the Lightning web component. The static reference is more efficient because it does not require a network call.

See Also