<!--- hasPermissions.stories.mdx --->

import { Meta } from '@storybook/addon-docs';

<Meta title="utils/hasPermissions" />

# hasPermissions

This util is used to check if a logged in user has the right to perform an action.

> It is best to also import the useRBACProvider hook in order to retrieve all the permissions of a user.

## Usage

```js
import { hasPermissions, useRBACProvider } from '@strapi/helper-plugin';

const Compo = () => {
  const { allPermissions } = useRBACProvider();
  const [{ isLoading, canAccess }, setState] = useState({ isLoading: true, canAccess: false });

  useEffect(() => {
    const checkPermission = async () => {
      try {
        const canAccess = await hasPermissions(allPermissions, [
          {
            action: 'plugin::content-manager.components.configure-layout',
            subject: null,
          },
        ]);

        setState({ isLoading: false, canAccess });
      } catch (err) {
        setState({ isLoading: false });
      }
    };

    checkPermission();
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);

  console.log({ isLoading, canAccess });

  return null;
};
```
