useOrganizationMemberships() hook
useOrganizationMemberships() is the raw organization-membership query that higher-level organization hooks build on top of. It loads the current user’s organization memberships with SWR and exposes the membership rows together with a manual refetch path.Usage
The following example shows a basic usage of useOrganizationMemberships().
export default function MembershipList() { const { organizationMemberships, loading } = useOrganizationMemberships(); if (loading) { return <p>Loading memberships…</p>; } return ( <ul> {organizationMemberships?.map((membership) => ( <li key={membership.id}>{membership.organization.name}</li> ))} </ul> );}Return value
The hook returns the following fields and methods.
›organizationMemberships: OrganizationMembershipWithOrganization[] | undefined;
organizationMemberships: OrganizationMembershipWithOrganization[] | undefined;Organization memberships for the current user.
›[].id?: string | undefined;
[].id?: string | undefined;Organization-membership identifier.
›[].organization?: Organization | undefined;
[].organization?: Organization | undefined;Organization attached to the membership.
›id?: string | undefined;
id?: string | undefined;Organization identifier.
›name?: string | undefined;
name?: string | undefined;Organization name.
›image_url?: string | undefined;
image_url?: string | undefined;Organization image URL.
›description?: string | undefined;
description?: string | undefined;Organization description.
›member_count?: number | undefined;
member_count?: number | undefined;Organization member count.
›[].user_id?: string | undefined;
[].user_id?: string | undefined;User identifier attached to the membership.
›[].roles?: OrganizationRole[] | undefined;
[].roles?: OrganizationRole[] | undefined;Roles attached to the membership.
›[].id?: string | undefined;
[].id?: string | undefined;Role identifier.
›[].name?: string | undefined;
[].name?: string | undefined;Role name.
›[].permissions?: string[] | undefined;
[].permissions?: string[] | undefined;Permissions granted by the role.
›[].public_metadata?: Record<string, unknown> | undefined;
[].public_metadata?: Record<string, unknown> | undefined;Public metadata stored on the membership.
›[].created_at?: string | undefined;
[].created_at?: string | undefined;Creation timestamp for the membership.
›[].updated_at?: string | undefined;
[].updated_at?: string | undefined;Last update timestamp for the membership.
›[].eligibility_restriction?: { type: "none" | "ip_not_allowed" | "mfa_required" | "ip_and_mfa_required"; message: string } | undefined | undefined;
[].eligibility_restriction?: { type: "none" | "ip_not_allowed" | "mfa_required" | "ip_and_mfa_required"; message: string } | undefined | undefined;Eligibility restriction attached to the membership when one exists.
›type?: "none" | "ip_not_allowed" | "mfa_required" | "ip_and_mfa_required" | undefined;
type?: "none" | "ip_not_allowed" | "mfa_required" | "ip_and_mfa_required" | undefined;Restriction type.
›message?: string | undefined;
message?: string | undefined;Restriction message.
›loading: boolean;
loading: boolean;Whether the shared client or the organization-memberships query is still loading.
›error: Error | undefined;
error: Error | undefined;Underlying SWR error for the organization-memberships query.
›refetch: () => Promise<void>;
refetch: () => Promise<void>;Revalidates the organization-memberships query.
How it works
This is the low-level membership query, not the higher-level organization list. That is why it returns membership rows rather than plain organizations.
Higher-level hooks such as
useOrganizationList(), useActiveOrganization(), and useActiveTenancy() all build on top of this membership data.The hook is SWR-backed, so
organizationMemberships can be undefined on the first render while the query is still resolving.Because it exposes membership rows directly, this is the right hook for permission-aware UI or any screen that needs role and membership metadata rather than only organization names.
When to use it
Examples
Render organization memberships
export default function OrganizationMembershipList() { const { organizationMemberships, loading } = useOrganizationMemberships(); if (loading) { return <p>Loading memberships…</p>; } return ( <ul> {organizationMemberships?.map((membership) => ( <li key={membership.id}> {membership.organization.name} ({membership.roles.length} roles) </li> ))} </ul> );}Refetch membership data after an external change
export default function RefreshMemberships() { const { refetch } = useOrganizationMemberships(); return <button onClick={() => refetch()}>Refresh memberships</button>;}