Can someone give me the code to get the current logged in user for a spfx webpart. I don't want pnp.sp or sp.web please, I want to use spHttpClient etc.
I cannot find the basic code ANYWHERE on the internet. A link will do.
Regards,
T
Can someone give me the code to get the current logged in user for a spfx webpart. I don't want pnp.sp or sp.web please, I want to use spHttpClient etc.
I cannot find the basic code ANYWHERE on the internet. A link will do.
Regards,
T
Sample code:
import { SPHttpClient, SPHttpClientResponse,ISPHttpClientOptions} from '@microsoft/sp-http';
this.context.spHttpClient.get(`${this.context.pageContext.web.absoluteUrl}/_api/SP.UserProfiles.PeopleManager/GetMyProperties`,
SPHttpClient.configurations.v1).then((response: SPHttpClientResponse) =>{
response.json().then((responseJSON: any) => {
console.log(responseJSON.DisplayName)
})
})