Monday, February 3, 2020

How to check current user is guest user or not in lightning web components(lwc)

To check the current user is a guest user, import the current user’s status from @salesforce/user/isGuest

Syntax
import isGuestUser from '@salesforce/user/isGuest';
isGuestuser identifier provides the guest user information if it returns true the current is a guest user or if it returns false current user not a guest user

HTML Code
<template>
    <lightning-card>
        <div class="slds-m-around_medium">
            <p>Current User is guest or not:  <b>{isGuestUser}</b></p>  
        </div>
 </lightning-card>
</template>

Javascript Controller
import { LightningElement } from 'lwc';
import isGuest from '@salesforce/user/isGuest';

export default class currentUserInfo extends LightningElement {
    isGuestUser = isGuest;
}

Output

No comments:

Post a Comment