top of page
  • Writer's pictureAndyH

Get current user


I needed to know who the current user is to customise my web part. The details are available through PnPJS.


Shantha Kumar Thambidurai came to the rescue. Here are the highlights.


First a new import from PnP's siteusers is needed:

import { CurrentUser } from '@pnp/sp/src/siteusers';

The details of the current user can then be retrieved:

sp.web.currentUser.get().then( ( r: CurrentUser ) => { // r[ 'Title' ] // r[ 'Email' ] });

Other properties are also available:

Id: number; Title: string; LoginName: string; PrincipalType: number; Email: string; IsHiddenInUI: boolean; IsShareByEmailGuestUser: boolean; IsSiteAdmin: boolean;

Check out Shantha's page for how to also get the groups the user is a member of.

32 views0 comments

Recent Posts

See All
bottom of page