Skip to main content

useActiveOrganization()

The useActiveOrganization() hook is arguably the most critical hook for maintaining data isolation in a B2B application. It retrieves the specific Organization object that the user has currently selected within their session context. It provides immediate access to the organization’s unique ID, its custom metadata, and—most importantly—provides rigorous utility functions for enforcing authorization gates on the frontend.

Import

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

Anatomy

loading
boolean
Boolean indicating SDK readiness.
activeOrganization
Organization | null
The complete initialized Organization profile of the currently active tenant.
activeMembership
OrganizationMembershipWithOrganization | null
The current user’s specific membership context within the active organization.
error
Error | null
Any error encountered during organization initialization.
refetch
() => Promise<void>
Manually triggers a re-fetch of the active organization and membership data.
Organization Management
Functions
Member & Role Management
Functions
Invitation Management
Functions
Domain Management
Functions
Enterprise Connections (SSO)
Functions
SCIM Directory Sync
Functions

Usage: Accessing Basic Org Data

You can use the organization object to stamp your UI with tenant-specific branding.
import { useActiveOrganization } from "@wacht/react-router";

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

  if (loading) return null;

  // Fallback UI if the user hasn't selected a team
  if (!activeOrganization) {
    return <h1>Personal Dashboard</h1>;
  }

  return (
    <header className="flex items-center gap-3">
      {activeOrganization.image && (
        <img src={activeOrganization.image as string} className="w-8 h-8 rounded-md" alt="Logo" />
      )}
      <h1 className="text-2xl font-bold tracking-tight text-zinc-900">
        {activeOrganization.name} Workspace
      </h1>
    </header>
  );
}

Client-Side Authorization (RBAC)

When building complex interfaces, certain destructive actions (like deleting a project or changing billing details) should only be accessible to users with specific roles. You can leverage the activeMembership.roles array or the global JWT session permissions to evaluate a user’s rights against the active organizational context.
[!WARNING] Client-side RBAC checks are excellent for UI/UX (hiding buttons or panels), but they are not a secure barrier. You must always re-verify permissions on your backend server by executing RequireAuth before executing destructive mutations to the database.