Permissions
React components and hooks to declaratively handle Merchant Center user permissions.
Installation
yarn add @commercetools-frontend/permissions
Additionally install the peer dependencies (if not present)
yarn add react
Hooks
Usage
import { useIsAuthorized } from '@commercetools-frontend/permissions';import { PERMISSIONS } from '../constants';const CreateButton = () => {const canManage = useIsAuthorized({demandedPermissions: [PERMISSIONS.Manage],});return (<PrimaryButtonisDisabled={!canManage}// .../>);};
Options
demandedPermissions: A list of user permissions of the customization that need to be evaluated against the applied user permissions.Multiple values can be provided, in which case the check becomes an
ANDcondition. However, this is discouraged and it's better to define theuseIsAuthorizedhook multiple times, one for each permission to be checked.