Below are some PnP methods to get user details
Get Email of user by User ID
private getEmail = (userId) => {
let web = new Web(siteUrl);
if (userId > 0 && !isNaN(parseInt(userId))) {
web.siteUsers.getById(userId).get().then(user => {
console.log('Email ID: ', user.Email);
}).catch(reject => console.error('Error getting Email of user by ID ', reject));
}
}
Get User Id by Email
private getIdByEmail = (email: string) => {
let web = new Web(siteUrl);
web.siteUsers.getByEmail(email).get().then(user => {
console.log('User Id: ', user.Id);
}).catch(reject => console.error('Error getting Id of user by Email ', reject));
}
Get Account Name of user by User Id
private getUserAccountName = (userId) => {
let web = new Web(siteUrl);
if (userId > 0 && !isNaN(parseInt(userId))) {
web.siteUsers.getById(userId).get().then(user => {
console.log('Account Name: ', user.LoginName);
}).catch(reject => console.error('Error getting Account Name of user by ID: ', reject));
}
}
Get User Name by User Id
private getUserName = (userId) => {
let web = new Web(siteUrl);
if (userId > 0 && !isNaN(parseInt(userId))) {
web.siteUsers.getById(userId).get().then(user => {
console.log('User Name: ', user.Title);
}).catch(reject => console.error('Error getting User Name by ID ', reject));
}
}
Get User ID of Current User
public getCurrentUserId() {
let web = new Web(siteUrl);
web.currentUser.get().then(user => {
console.log('current user detail: ', user.Id);
}).catch(err => console.error('Error getting current user details: ', err));
}