# How to get current user details in sharepoint custom webparts?

**URL:** <https://techcommunity.softwareag.com/t/how-to-get-current-user-details-in-sharepoint-custom-webparts/267376>\
**Category:** Knowledge base\
**Tags:** UI, sharepoint, webparts, SPFX, ReactJS, Custom-Webparts\
**Created:** [December 15, 2022, 10:05am UTC](https://techcommunity.softwareag.com/t/how-to-get-current-user-details-in-sharepoint-custom-webparts/267376 "2022-12-15T10:05:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vivek.Chadha](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@Vivek.Chadha](https://techcommunity.softwareag.com/u/Vivek.Chadha)\
**Post date:** [December 15, 2022, 10:05am UTC](https://techcommunity.softwareag.com/t/how-to-get-current-user-details-in-sharepoint-custom-webparts/267376/1 "2022-12-15T10:05:04Z")

</div>

## Problem Statement

How to capture the user details like user id and user email id, user login name, and user office in Sharepoint web part?

## Solution

### Step 1

- Do npm install sp-pnp-js

### Step 2

- Go to the component file and put the import { Web } from “sp-pnp-js”;

### Step 3

- Create a method and make a rest call by using sp-pnp-js, below is the sample code for the same.

```auto
public getUserDetails(){
 
    let web = new Web(this.props.context.pageContext.web.absoluteUrl);  
    return web.currentUser.get().then((user) => {
     return user;
     });
}

```

You can call this method and store the returned user data from this method and use it.

### Step 4

- You can access this user information by user.Email , user.Email.

This will help you to get the user details.

Thank you
