0

I'm trying to check if a user has permissions in a list with @pnp/sp but depends on the URL that I'm in is working or not.

public async getUserPermissions(pageContext: PageContext, listname: string) : Promise<boolean>{
        const web: Web = new Web(pageContext.web.absoluteUrl);
        return await web.lists.getByTitle(listname).currentUserHasPermissions(PermissionKind.EditListItems);
    }

I include a console.log of pageContext.web.absoluteUrl and it is always correct "https://xxxx.sharepoint.com/sites/xxx"

Sergio
  • 74
  • 8

1 Answers1

0

Finally, I solve my problem with the next code:

public async getUserPermissions(pageContext: PageContext, listname: string) : Promise<boolean>{
        sp.setup({
            sp: {
              baseUrl: pageContext.web.absoluteUrl
            }
          });
        return await sp.web.lists.getByTitle(listname).currentUserHasPermissions(PermissionKind.EditListItems);
    }

The problem was that my service it is outside of my webpart folder, for that reason I don't know why (I will ask to pnp users), it doesn´t create the Web object correctly...

Sergio
  • 74
  • 8