NewWacht Bench is live — AI-assisted development for Wacht

useActiveOrganization() hook

useActiveOrganization() is the active-scope wrapper over useOrganizationList(). It resolves the current active organization and active organization membership from the session, then rebinds the organization-level management methods so they operate on that active organization automatically.

Usage

The following example shows a basic usage of useActiveOrganization().

export default function ActiveOrgHeader() {  const { activeOrganization, loading } = useActiveOrganization();  if (loading) {    return <p>Loading organization…</p>;  }  return <p>{activeOrganization?.name ?? 'No active organization'}</p>;}

Return value

The hook returns the following fields and methods.

activeOrganization: Organization | null;
Organization whose membership identifier matches the active sign-in in the session.
id?: string | undefined;
Organization identifier.
name?: string | undefined;
Organization name.
image_url?: string | undefined;
Organization image URL.
description?: string | undefined;
Organization description.
member_count?: number | undefined;
Organization member count.
enforce_mfa?: boolean | undefined;
Whether the organization enforces MFA.
activeMembership: OrganizationMembershipWithOrganization | null;
Current active organization membership resolved from the session.
id?: string | undefined;
Organization-membership identifier.
organization?: Organization | undefined;
Organization attached to the active membership.
roles?: OrganizationRole[] | undefined;
Roles attached to the active membership.
[].id?: string | undefined;
Role identifier.
[].name?: string | undefined;
Role name.
[].permissions?: string[] | undefined;
Permissions granted by the role.
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.
loading: boolean;
Whether the session or the underlying organization list is still loading.
error: Error | null;
Combined loading error from the session branch or the organization-list branch.
refetch?: () => Promise<void> | undefined;
Revalidates the underlying organization memberships query.
getRoles?: () => Promise<OrganizationRole[]> | undefined;
Loads roles for the active organization.
getMembers?: () => Promise<PaginatedResponse<OrganizationMembership[]> | []> | undefined;
Loads members for the active organization.
updateOrganization?: (update: OrganizationUpdate) => Promise<ApiResult<Organization> | []> | undefined;
Updates the active organization.
getDomains?: () => Promise<OrganizationDomain[] | []> | undefined;
Loads domains for the active organization.
addDomain?: (domain: NewDomain) => Promise<ApiResult<OrganizationDomain> | undefined> | undefined;
Adds a domain to the active organization.
verifyDomain?: (domain: OrganizationDomain) => Promise<ApiResult<OrganizationDomain> | undefined> | undefined;
Verifies one domain on the active organization.
removeDomain?: (domain: OrganizationDomain) => Promise<ApiResult<OrganizationDomain> | undefined> | undefined;
Removes one domain from the active organization.
getInvitations?: () => Promise<OrganizationInvitation[] | []> | undefined;
Loads invitations for the active organization.
removeMember?: (member: OrganizationMembership) => Promise<void | []> | undefined;
Removes a member from the active organization.
addMemberRole?: (member: OrganizationMembership, role: OrganizationRole) => Promise<OrganizationMembership | undefined> | undefined;
Adds a role to a member in the active organization.
removeMemberRole?: (member: OrganizationMembership, role: OrganizationRole) => Promise<OrganizationMembership | undefined> | undefined;
Removes a role from a member in the active organization.
inviteMember?: (invitationPayload: OrganizationInvitationPayload) => Promise<OrganizationInvitation | undefined> | undefined;
Invites a member into the active organization.
discardInvitation?: (invitation: OrganizationInvitation) => Promise<OrganizationInvitation | undefined> | undefined;
Discards an invitation from the active organization.
resendInvitation?: (invitation: OrganizationInvitation) => Promise<OrganizationInvitation | undefined> | undefined;
Resends an invitation from the active organization.
leave?: () => Promise<void | undefined> | undefined;
Leaves the active organization.
removeRole?: (role: OrganizationRole) => Promise<void | undefined> | undefined;
Removes a role from the active organization.
getEnterpriseConnections?: () => Promise<EnterpriseConnection[] | []> | undefined;
Loads enterprise connections for the active organization.
createEnterpriseConnection?: (payload: CreateEnterpriseConnectionPayload) => Promise<EnterpriseConnection | undefined> | undefined;
Creates an enterprise connection on the active organization.
updateEnterpriseConnection?: (connectionId: string, payload: UpdateEnterpriseConnectionPayload) => Promise<EnterpriseConnection | undefined> | undefined;
Updates an enterprise connection on the active organization.
deleteEnterpriseConnection?: (connectionId: string) => Promise<void | undefined> | undefined;
Deletes an enterprise connection on the active organization.
testEnterpriseConnectionConfig?: (payload: { protocol: 'saml' | 'oidc'; idp_entity_id?: string; idp_sso_url?: string; idp_certificate?: string; oidc_issuer_url?: string; oidc_client_id?: string; oidc_client_secret?: string }) => Promise<{ success: boolean; protocol: string; checks: Record<string, boolean>; errors?: Record<string, string> } | null> | undefined;
Tests an enterprise-connection configuration for the active organization.
testEnterpriseConnection?: (connectionId: string) => Promise<{ success: boolean; protocol: string; checks: Record<string, boolean>; errors?: Record<string, string> } | null> | undefined;
Tests an existing enterprise connection on the active organization.
generateSCIMToken?: (connectionId: string) => Promise<SCIMTokenInfo | undefined> | undefined;
Generates a SCIM token for an enterprise connection on the active organization.
getSCIMToken?: (connectionId: string) => Promise<SCIMTokenInfo | undefined> | undefined;
Loads SCIM token information for an enterprise connection on the active organization.
revokeSCIMToken?: (connectionId: string) => Promise<void | undefined> | undefined;
Revokes the SCIM token for an enterprise connection on the active organization.

How it works

This hook is not a separate data source. It wraps useOrganizationList() and useSession(), then resolves one active organization and one active membership from the current session.
All of the management methods are rebound to the current active organization, so callers no longer pass an organization argument each time.
When there is no active organization, many methods return [], null, or undefined instead of throwing. The docs reflect that behavior because it is part of the current implementation contract.
The loading branch is a true union. While either the session or the organization list is still loading, the mutation methods are unavailable.
This is the right hook for organization-aware pages such as settings, members, invitations, domains, and enterprise SSO screens that should always operate on the active organization only.

When to use it

    Examples

    Render the active organization name

    export default function ActiveOrganizationTitle() {  const { activeOrganization, loading } = useActiveOrganization();  if (loading) {    return <p>Loading organization…</p>;  }  return <p>{activeOrganization?.name ?? 'No active organization'}</p>;}

    Load members for the active organization

    export default function ActiveOrganizationMembers() {  const { loading, getMembers } = useActiveOrganization();  async function loadMembers() {    if (loading) {      return;    }    const result = await getMembers();    console.log(result);  }  return <button onClick={loadMembers}>Load members</button>;}

    Invite a member into the active organization

    export default function InviteMemberButton() {  const { loading, inviteMember } = useActiveOrganization();  async function invite() {    if (loading) {      return;    }    await inviteMember({      email: 'jane@example.com',      organizationRole: {        id: 'role_123',        organization_id: 'org_123',        name: 'Admin',        permissions: ['org:manage'],        created_at: '',        updated_at: '',      },    });  }  return <button onClick={invite}>Invite member</button>;}

    On this page