Get Current User Info in LWC

by Rijwan Mohmmed

Hello friends, today we will discuss Get Current User Info in LWC. We can get current User info like Id, Name, Email, IsActive, and Alias details without apex class.  In Salesforce Lightning Web Component (LWC), we use the UIRecordApi property to display the current User detail.

Also, check this : Lookup Field in LWC Datatable Inline Edit


Key Highlights :

  1. We don’t need apex class to get Current User info.
  2. We can fetch the Username, User Email, and User Id.
  3. We use UIRecordApi to get records.
  4. We can get the Current User Id just import.

Process & Code :

Get Current User Id :

import Id from '@salesforce/user/Id';

lWCCurrentUserInfo.Html :

    <!-----header start-------->
    <div class="slds-tabs_card">
		<div class="slds-page-header">
			<div class="slds-page-header__row">
				<div class="slds-page-header__col-title">
					<div class="slds-media">
						<div class="slds-media__figure">
							<span class="slds-icon_container slds-icon-standard-opportunity">
								 <lightning-icon icon-name="standard:recipe" alternative-text="recipe" title="recipe"></lightning-icon>
						<div class="slds-media__body">
							<div class="slds-page-header__name">
								<div class="slds-page-header__name-title">
										<span>Get Current User Info in LWC</span>
										<span class="slds-page-header__title slds-truncate" title="Recently Viewed">TechDicer</span>
	</div> <br/>
    <!-----header end-------->
    <!-----User info Card --->
    <lightning-card  variant="Narrow"  title="Get Current User Info in LWC" icon-name="standard:user">
        <div class="slds-box slds-m-around_medium">
            <p><b>User Id :</b> {userId}</p>
            <p><b>User Name :</b> {currentUserName}</p>
            <p><b>User Email :</b> {currentUserEmail}</p>
            <p><b>User Is Active :</b> {currentIsActive}</p>
            <p><b>User Alias :</b> {currentUserAlias}</p>
    <!-----/User info Card -->


import { LightningElement, wire, track } from 'lwc';
import Id from '@salesforce/user/Id';
import { getRecord } from 'lightning/uiRecordApi';
import UserNameFIELD from '@salesforce/schema/User.Name';
import userEmailFIELD from '@salesforce/schema/User.Email';
import userIsActiveFIELD from '@salesforce/schema/User.IsActive';
import userAliasFIELD from '@salesforce/schema/User.Alias';
export default class LWCCurrentUserInfo extends LightningElement {
    @track error;
    @track userId = Id;
    @track currentUserName;
    @track currentUserEmail;
    @track currentIsActive;
    @track currentUserAlias;

    @wire(getRecord, { recordId: Id, fields: [UserNameFIELD, userEmailFIELD, userIsActiveFIELD, userAliasFIELD ]}) 
    currentUserInfo({error, data}) {
        if (data) {
            this.currentUserName = data.fields.Name.value;
            this.currentUserEmail = data.fields.Email.value;
            this.currentIsActive = data.fields.IsActive.value;
            this.currentUserAlias = data.fields.Alias.value;
        } else if (error) {
            this.error = error ;

Output :


Reference :

  1. LWC get record Api

What’s your Reaction?

You may also like

Leave a Comment