Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The function sp.web.currentUserHasPermissions is undefined #3189

Open
Srutututu opened this issue Jan 10, 2025 · 1 comment
Open

The function sp.web.currentUserHasPermissions is undefined #3189

Srutututu opened this issue Jan 10, 2025 · 1 comment

Comments

@Srutututu
Copy link

What version of PnPjs library you are using

4.x

Minor Version Number

8.0

Target environment

SharePoint Framework

Additional environment details

SPFX 1.20; Node 18.19.1; Typescript 4.7.4.

Question/Request

I've installed PnPJS in my SPFX app according to the example here:
https://github.com/pnp/pnpjs/blob/version-4/samples/spfx-react-components/README.md

Then I wanted to get the current user permissions using the documentation here:
https://pnp.github.io/pnpjs/sp/permissions/#user-has-permissions

Modules I imported are:
image

I then try to run a simple function (after initializing _sp), exactly as in the documentation:

const currentUser = await this._sp.web.currentUser();
const isOwner = await this._sp.web.userHasPermissions(currentUser.LoginName, PermissionKind.ManagePermissions);

Here however I get the exception "userHasPermissions is not a function" in the Console, and "undefined" when debugging.

It's clearly not correctly imported. How do I import "userHasPermissions" and "currentUserHasPermissions" in PnP 4.0?

@bcameron1231
Copy link
Collaborator

bcameron1231 commented Jan 10, 2025

Hi. It looks like our docs may be missing the import in a couple of the examples.

Make sure to import

import "@pnp/sp/security";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants