Cerbos JavaScript SDK
    Preparing search index...

    Function useIsAllowed

    • Check if the principal is allowed to perform an action on a resource.

      Parameters

      Returns AsyncResult<boolean>

      import { useIsAllowed } from "@cerbos/react";

      function SomeComponent() {
      const check = useIsAllowed({
      resource: {
      kind: "document",
      id: "1",
      attr: { owner: "user@example.com" },
      },
      action: "view",
      });

      if (check.isLoading) {
      // show spinner
      return "Loading...";
      }

      if (check.error) {
      // handle error
      return "Error...";
      }

      return <div>{check.data && <button>a button document 1</button>}</div>;
      }