How to Get Current logged in user id in SPFx using React Typescript

Technology Specialist
March 21, 2018
Rate this article
[Total: 0    Average: 0/5]

We can’t use _spPageContextInfo inside a SPFx webpart, hence to get the current logged-in user name, email etc except user id please make use of below syntax.

this.context.pageContext.user doesn’t include id or userId

When I don’t want to make a rest call or other methods to get the current user Id!!!

Here is the solution

Add import pnp from ‘sp-pnp-js’; in the top of webpart.ts file


Use the node.js command prompt to install below command to avoid the missing module error

npm install sp-pnp-js –save

Add the below code to your webpart.ts file


this. getUserId (email);

public getUserId(email: string): Promise<number> {

return => {





Thank you!

Category : React, SharePoint, SPFx

Author Info

Technology Specialist
Rate this article
[Total: 0    Average: 0/5]
Having 6 years of experience in design and development of SharePoint applications, Mani has expertise in developing applications using Office 365, SharePoint 2013 & 2010, SPFX, SP Designer Workflows, Visual more

Leave a comment