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);
}
- https://xxxx.sharepoint.com/sites/xxx/_layouts/15/workbench.aspx CORRECT Request URL: https://xxxx.sharepoint.com/sites/xxx/_api/web/currentuser?$select=LoginName
- https://xxxx.sharepoint.com/sites/xxx WRONG Request URL: https://xxxx.sharepoint.com/sites/_api/web/currentuser?$select=LoginName
- https://xxxx.sharepoint.com/sites/xxx/ CORRECT Request URL: https://xxxx.sharepoint.com/sites/xxx/_api/web/currentuser?$select=LoginName
- https://xxxx.sharepoint.com/sites/xxx/SitePages/xxx.aspx WRONG Request URL: https://xxxx.sharepoint.com/sites/xxx/SitePages/_api/web/currentuser?$select=LoginName
I include a console.log of pageContext.web.absoluteUrl and it is always correct "https://xxxx.sharepoint.com/sites/xxx"