Cerbos JavaScript SDK
    Preparing search index...

    Function useCheckResource

    • Check the principal's permissions on a resource.

      Parameters

      Returns AsyncResult<CheckResourcesResult>

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

      function SomeComponent() {
      const check = useCheckResource({
      resource: {
      kind: "document",
      id: "1",
      attr: { owner: "user@example.com" },
      },
      actions: ["view", "edit"],
      });

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

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

      return (
      <div>
      {check.data.allAllowed() && <button>a button</button>}
      {check.data.isAllowed("view") && <button>another button</button>}
      </div>
      );
      }