useHasPermission

useHasPermission(
	permissionKinds: PermissionKind | PermissionKind[],
	options?: UserPermissionOptions,
	deps?): boolean | null | undefined;

Returns true if user has permission on scope. If not returns false. Use UserPermissionOptions.userId for another user and UserPermissionOptions.scope for permission scope. Default is current user permission on current web scope.

Examples

Check current users web permissions,

import { PermissionKind } from "@pnp/sp/security";
import { useHasPermission } from "pnp-react-hooks";

const permissions = PermissionKind.ViewListItems | PermissionKind.ViewPages
const hasPermission = useHasPermission(permissions);

Check another users permission on web,

import { PermissionKind } from "@pnp/sp/security";
import { useHasPermission } from "pnp-react-hooks";

const permissions = PermissionKind.ViewListItems | PermissionKind.ViewPages
const userHasPermission = useHasPermission(permissions, {
	userId: "user@example.onmicrosoft.com"
});

Check list permissions,

import { PermissionKind } from "@pnp/sp/security";
import { useHasPermission } from "pnp-react-hooks";

const permissions = PermissionKind.ViewListItems | PermissionKind.ViewPages
const hasPermission = useHasPermission(permissions, {
	scope: {
		list: "My List Title"
	}
});

Check item permissions,

import { PermissionKind } from "@pnp/sp/security";
import { useHasPermission } from "pnp-react-hooks";

const permissions = PermissionKind.ViewListItems | PermissionKind.ViewPages
const hasPermission = useHasPermission(permissions, {
	scope: {
		list: "My List Title",
		item: 12
	}
});

Parameters

NameTypeDescriptionTracked for changes
permissionKindsPermissionKind | PermissionKind[]SP permission kind array or valueYes
options?UserPermissionOptionsuseHasPermission hook optionsPartially
deps?DependencyListHook dependency list.Yes