useCapxulCurrentUser
Query hook for the aggregated current-user context — user, personal account, and organization memberships in one read.
Reads the aggregated current-user context: who is signed in, their
personal account, and every organization they belong to — one query instead of
composing useCapxulProfile,
useCapxulAccountBalance,
and useCapxulOrgs yourself. Built for entity switchers and app shells.
Import
import { useCapxulCurrentUser } from "@capxul/sdk-react";Usage
"use client";
import { useCapxulCurrentUser } from "@capxul/sdk-react";
function EntitySwitcher() {
const currentUser = useCapxulCurrentUser();
if (currentUser.isLoading) return <p>Loading…</p>;
if (currentUser.error) return <p>{currentUser.error.message}</p>;
const { user, organizations } = currentUser.data;
return (
<nav>
<p>{user.displayName ?? user.email} (personal)</p>
<ul>
{organizations.map((org) => (
<li key={org.id}>
{org.name} — {org.role}
</li>
))}
</ul>
</nav>
);
}This is a signed-in surface: it reads the current user, so gate it on
useCapxulSession (or pass
enabled: false) while signed out.
Parameters
options
{ enabled?: boolean } | undefined
| Field | Type | Description |
|---|---|---|
enabled | boolean | undefined | Set false to skip the read (for example while signed out). Defaults to true. |
Return type
import { type UseCapxulCurrentUserReturn } from "@capxul/sdk-react";
// UseQueryResult<CurrentUserContext, CapxulError>data is a CurrentUserContext:
| Field | Type | Description |
|---|---|---|
user | object | id, email, displayName, plus handle and paymentLink. |
personalAccount | object | null | The personal Account: its opaque id and its address (null until the account is activated on the network). |
organizations | array | One entry per membership: id, name, handle, role (your role label in that org), and the org's account (id + address). |
In the published alpha, user.handle and user.paymentLink are always
null — payment handles are not populated on this surface yet. See
Capability status.
The hook returns TanStack Query's UseQueryResult. The most-used fields:
| Field | Description |
|---|---|
data | The query data (typed per hook, shown above). undefined until the first success. |
error | A CapxulError when the last fetch failed, otherwise null. |
status | 'pending' | 'error' | 'success'. |
isLoading | true during the first fetch (no data yet). |
isFetching | true whenever a fetch is in flight, including background refetches. |
refetch | Manually 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", "currentUser"] — no SDK mutation invalidates this key
automatically today (it is not part of the auth-boundary invalidation that
covers session/profile/account). After sign-in, sign-out, or creating an
organization, call refetch() — or remount the screen — to pick up the new
context.
Client method
This hook wraps client.currentUser.get() on the core SDK.