GET LOGIN NAME OR EMAIL IN ONE LINE (SHAREPOINT ONLINE)

GET LOGIN NAME OR EMAIL IN ONE LINE (SHAREPOINT ONLINE)

SharePoint is a powerful tool for businesses to manage their documents, workflows, and collaboration. However, there are times when you need to retrieve a user's login name in order to complete certain tasks. While it may seem like a complex process, there is a simple way to get a user's login name in just one line of code. In this blog post, we'll show you how to easily retrieve a SharePoint user's login name using one line of code.

.

The solution is to access the page context.

Copy and paste the below line to get.

// Get current login name / Display name

this.context.pageContext.legacyPageContext['userDisplayName'];

// Get current login Email

this.context.pageContext.legacyPageContext['userEmail']);

Click here to see the complete list of the object's properties