Capxul Docs
HooksOrganizations

useCapxulOrgRoles

Query hook for the roles defined on an organization, scoped by org id.

Reads the roles a member can be invited into for an Organization — the roles that carry member-management authority. A Budget is granted, never offered as a job title, so it is not in this list. Role labels and stored spend caps do not authorize an L2 payment. Use the Organization Permission hooks for current authority.

Import

import { useCapxulOrgRoles } from "@capxul/sdk-react";

Usage

"use client";

import type { OrgId } from "@capxul/sdk";
import { useCapxulOrgRoles } from "@capxul/sdk-react";

function RoleList({ orgId }: { orgId: OrgId }) {
  const roles = useCapxulOrgRoles(orgId);

  if (roles.isPending) return <p>Loading roles…</p>;
  if (roles.error) return <p>{roles.error.message}</p>;

  return (
    <ul>
      {roles.data.map((role) => {
        const perTx = role.definition.spend?.perTx;
        return (
          <li key={role.roleKey}>
            {role.label}
            {perTx
              ? ` — up to ${perTx.value} ${perTx.currency} per transaction`
              : " — no per-transaction cap"}
          </li>
        );
      })}
    </ul>
  );
}

Parameters

orgId

OrgId | undefined

The organization whose roles to read. The query stays disabled while orgId is undefined. When the screen must wait for Organization setup, derive options.enabled from the matching ready Organization lane in useCapxulIdentity. A disabled query remains isPending until the gate opens.

options

UseCapxulOrgRolesOptions | undefined

Prop

Type

Return type

import { type UseCapxulOrgRolesReturn } from "@capxul/sdk-react";
// UseQueryResult<readonly RoleView[], CapxulError>

data is a list of RoleView records:

FieldTypeDescription
orgIdOrgIdThe org the role is defined on.
labelstringThe role's display label (for example "Owner").
roleKeyRoleKeyThe enforced key, derived deterministically from the label.
definitionRoleDefinitionThe full role definition (below).

A RoleDefinition carries:

FieldTypeDescription
labelstringThe role's label.
spendRoleSpendCap | undefinedHistorical role metadata. It does not authorize an L2 payment.
canManageMembersboolean | undefinedWhether the role can invite and remove members.
canManageRolesboolean | undefinedWhether the role can manage the role set itself.

The hook returns TanStack Query's UseQueryResult. The most-used fields:

FieldDescription
dataThe query data (typed per hook, shown above). undefined until the first success.
errorA CapxulError when the last fetch failed, otherwise null.
status'pending' | 'error' | 'success'.
isLoadingtrue during the first fetch (no data yet).
isFetchingtrue whenever a fetch is in flight, including background refetches.
refetchManually refetch the query.

Capxul query hooks stay pending until the provider finishes bootstrapping — you do not need to gate them on useCapxul() yourself. The full field list is in the TanStack Query useQuery reference; see also the TanStack Query integration guide.

Query key

["capxul", "org", orgId, "roles"] — org-scoped.

Client method

This hook wraps client.org(orgId).roles() — the entity-scoped org bundle on the core SDK.

On this page