<OrganizationSwitcher />
The <OrganizationSwitcher /> is the cornerstone UI component for any B2B, multi-tenant application built on Wacht. It provides users with a clean, interactive dropdown menu to rapidly switch their active context between different organizations they belong to.
Additionally, it serves as an intuitive portal for users to create brand new organizations or accept pending group invites directly from the interface.
Import
Usage
You will typically place this component adjacent to the<UserButton /> in your application’s primary navigation header.
The “Context Switch” Architecture
When a user selects a different organization from the dropdown, it isn’t just updating a piece of state—Wacht executes a highly complex “Context Switch” behind the scenes:- Session Update: The global Wacht session locally updates the
activeOrganizationId. - Token Minting: The SDK immediately connects to the Wacht backend to fetch a fresh JWT session token. This new token contains the user’s specific RBAC (Role-Based Access Control) permissions strictly scoped to the newly selected organization.
- Reactivity: Any React components or data-fetching libraries (like React Query or Apollo) that hook into Wacht’s session state will automatically re-render or re-validate. This guarantees that your application never accidentally bleeds data between tenants.
Conditional Rendering
The<OrganizationSwitcher /> is intelligent. If the currently authenticated user is not a member of any organizations, the component gracefully declines to mount and remains invisible.
Because of this, you should ensure you provide a dedicated onboarding pathway—such as rendering a <CreateOrganizationForm /> on an empty dashboard—so brand new users can establish their first organizational context.
