Skip to main content

useActiveOrganization()

The useActiveOrganization() hook serves as a critical primitive for enforcing data isolation boundaries within segmented B2B architectures. It yields the specific Organization object contextually bound to the user’s active session. This hook exposes the active organization’s unique identifier, custom metadata matrix, and authorization evaluation functions, facilitating robust client-side access control.

Hook Import

import { useActiveOrganization } from "@wacht/tanstack-router";

Hook Interface

loading
boolean
Boolean flag denoting the initialization readiness of the SDK concerning the organization context.
activeOrganization
Organization | null
The fully hydrated Organization profile correlating to the actively selected tenant. Evaluates to null if no selection exists.
activeMembership
OrganizationMembershipWithOrganization | null
The authenticated user’s specific membership construct nested within the active organization parameter.
error
Error | null
Captures network failures or processing exceptions encountered during the organization context initialization.
refetch
() => Promise<void>
Triggers a manual network synchronization sequence for the active organization and membership data.
Organization Management Controls
Functions
Member & Role Authorizations
Functions
Invitation Dispatch
Functions
Domain Validations
Functions
Enterprise Single Sign-On Integrations
Functions
SCIM Directory Synchronizations
Functions

Implementation Guidelines

Accessing Top-Level Organization Parameters

The activeOrganization construct supplies the context required for rendering tenant-specific branding elements and interface parameters dynamically.
import { useActiveOrganization } from "@wacht/tanstack-router";

export function TenancyDashboardHeader() {
  const { loading, activeOrganization } = useActiveOrganization();

  if (loading) return null;

  // Utilize fallback interface structures if the user has not confirmed an organization selection context.
  if (!activeOrganization) {
    return <h1 className="font-medium text-gray-800 tracking-tight">Personal Workspace Context</h1>;
  }

  return (
    <header className="flex items-center gap-4">
      {activeOrganization.image && (
        <img src={activeOrganization.image as string} className="w-8 h-8 rounded-md" alt="Organization Brand Logo" />
      )}
      <h1 className="text-2xl font-semibold tracking-tight text-gray-900 border-b border-gray-100 pb-2">
        {activeOrganization.name} Context
      </h1>
    </header>
  );
}

Client-Side Authorization Modeling (RBAC)

Interface elements invoking destructive mutations (e.g., resource deletion, billing manipulation) must be programmatically restricted to users possessing explicit role assignments. The activeMembership.roles construct furnishes the arrays necessary to evaluate authorization checks.
[!WARNING] Client-side RBAC evaluations dictate interface rendering logic but do not enforce absolute security boundaries. System integrity necessitates comprehensive policy verification explicitly executed upon the backend server infrastructure utilizing the RequireAuth mechanisms prior to database modification events.