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

Technology Specialist
Published On :   21 Mar 2018
Visit Count
Today :  13    Total :   3800

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!