3

What's the best way to check the running users custom permission in an Aura component?

I can only find documentation around LWC but in this instance I have to use Aura.

1
  • I added another method that avoids the use of apex by using an lwc inside your aura component. Commented Dec 9, 2022 at 3:53

2 Answers 2

1

You can check whether a user has a Custom Permission within the Apex controller for your Aura component. If you do this within the onInit method, you can then store whether or not the user has that Custom Permission to drive logic in your component.

The code in Apex is quick simple now, you can use something like the following:

@AuraEnabled
public static Boolean hasCustomPermission(){
    return FeatureManagement.checkPermission('your_custom_permission_api_name');
}
2

Since you can have a lwc inside an aura one, you could make a special permission check component eg permission-checker and include any permissions you might need to check in it.

import doTheThing from '@salesforce/customPermission/doTheThing';

export default class PermissionChecker extends LightingElement {

    @api can(permission) {
      if (permission == 'doTheThing'){
        return doTheThing;
      }
      //etc (this could also be a case statement)
      return false;
    }
}

Then include this in your aura component:

<c:permissionChecker aura:id="permission-checker"></c:permissionChecker>

Then invoke:

let canDoTheThing = component.find('permission-checker').can("doTheThing");   

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .