About Me

My photo
PLANO, Texas, United States

Friday, October 30, 2020

Check User Permissions for Lightning Web Components

Security is a key aspect of any application. LWC ensures security. If you want to display any component to a specific user, you can align the permission and validate it in your LWC.

Customize a component’s behavior based on whether the current user has a specific permission. To check a user’s permission assignment, import Salesforce permissions from the @salesforce/userPermission and @salesforce/customPermission scoped modules.



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


import hasPermission from '@salesforce/userPermission/PermissionName';

import hasPermission from '@salesforce/customPermission/PermissionName';


import { LightningElement } from 'lwc';

import hasPermission from '@salesforce/userPermission/ViewSetup';

export default class LWC_hasPermission_demo extends LightningElement {

   get isSetupEnabled() {

       return hasPermission;

   }

}


<template>

   <common-view></common-view>

 

   <template if:true={isReportVisible}>

      You have permission

   </template>

</template>


No comments:

Post a Comment