TypeScript (Developer Preview)
Static Resources
Content Asset Files
SVG Resources
Labels
Internationalization
Current User ID
Current Community
Permissions
Client Form Factor
Mobile-Ready Components
Develop Secure Code
To get information about the current user, use the @salesforce/user scoped module.
1import property from "@salesforce/user/property";property—The supported properties are Id, which is the user’s ID, and isGuest, which is a boolean value indicating whether the user is a guest user. Use the isGuest property to check whether or not the user is authenticated in the Experience Builder site.This sample code imports the current user ID and assigns it to the userId property to provide access in the HTML template.
1import { LightningElement } from 'lwc';
2import Id from '@salesforce/user/Id';
3
4export default class MiscGetUserId extends LightningElement {
5 userId = Id;
6}To reference a user ID in a template, use {property} syntax, which is the same syntax you use to reference any JavaScript property.
1<!-- miscGetUserId -->
2<template>
3 <lightning-card title="MiscGetUserId" icon-name="custom:custom19">
4 <div class="slds-m-around_medium">
5 <p>User Id:</p>
6 {userId}
7 </div>
8 </lightning-card>
9</template>You can use @salesforce/user in a TypeScript file. This scoped module corresponds to the user.d.ts type definition in the @salesforce/lightning-types npm package.
Note
See Also