1

I'm trying to get the user context in my React web part and I am getting 404's when requesting: https://localhost:4321/_api/web/currentuser

This is the part of the code that fetches the current user:

private GetUserProperties(): void {
/*
pnp.setup({
  spfxContext: this.context
});
 */

pnp.sp.web.currentUser.get().then((r: CurrentUser) => {
  console.log('CURRENT USER', r);
});
}

This was setup as a SharePoint online application. I've tried several different solutions with no luck.

2 Answers 2

0

You are trying to get user details through local machine. The API you are using is a SharePoint REST API and for that you will need a SharePoint site and access to the site to get the current user details by using the following URL:

https://Your_SharePoint_Site_Url/_api/web/currentuser

0

You commented out the bit you needed. You need to run the setup with the context.

private GetUserProperties(): void {
  pnp.setup({
    spfxContext: this.context
  });
  pnp.sp.web.currentUser.get().then((r: CurrentUser) => {
    console.log('CURRENT USER', r);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.