Documentation Index
Fetch the complete documentation index at: https://docs.vertz.dev/llms.txt
Use this file to discover all available pages before exploring further.
TenantProvider gives your app tenant switching: list tenants, switch between them, auto-resolve the default, and track loading state. Wrap your app (inside AuthProvider), use useTenant() to read state, and drop in TenantSwitcher for a ready-made UI — or build your own.
Quick start
1. Wrap your app
TenantProvider must be inside AuthProvider. Pass the SDK methods generated by codegen:
2. Drop in the switcher
3. Or build a custom UI with the hook
TenantProvider
Fetches the tenant list on mount and provides tenant state to all children via context.| Prop | Type | Description |
|---|---|---|
listTenants | () => Promise<Result<ListTenantsResponse>> | SDK method to fetch tenants (generated by codegen) |
switchTenant | SdkMethod<{ tenantId: string }> | SDK method to switch tenant (generated by codegen) |
onSwitchComplete | (tenantId: string) => void | Called after a successful switch — use for navigation |
children | unknown | App content |
TenantProvider must be rendered inside AuthProvider. It reads from AuthContext internally —
you don’t need to pass auth state manually.Automatic query invalidation on tenant switch
WhenswitchTenant() succeeds, all active tenant-scoped queries are automatically invalidated. Cached data from the previous tenant is cleared immediately (no stale cross-tenant data visible), then each query refetches with the new tenant context. Non-tenant-scoped queries (e.g., global settings) are left untouched.
This happens automatically — no manual invalidation or onSwitchComplete callback needed for data freshness.
useTenant()
Returns reactive tenant state. All signal properties are auto-unwrapped by the compiler.| Property | Type | Description |
|---|---|---|
tenants | TenantInfo[] | All tenants the user belongs to |
currentTenantId | string | undefined | Tenant in the current session |
lastTenantId | string | undefined | Last tenant the user switched to |
resolvedDefaultId | string | undefined | Server-recommended default tenant |
isLoading | boolean | true while fetching tenants |
switchTenant | (tenantId: string) => Promise<Result<void, Error>> | Switch to a different tenant |
TenantInfo
TenantSwitcher
A ready-made dropdown component that renders the current tenant with a menu to switch. Import from@vertz/ui-auth:
| Prop | Type | Default | Description |
|---|---|---|---|
renderItem | (tenant: TenantInfo) => unknown | Renders tenant.name | Custom render for each tenant item (trigger and dropdown) |
className | string | — | CSS class for the container |
Styling
TenantSwitcher uses data-part attributes for styling:
| Part | Element | Description |
|---|---|---|
tenant-switcher | Container div | Root wrapper |
trigger | button | Shows the current tenant |
content | div | Dropdown panel |
item | button | Individual tenant option |
data-selected="true" when they match the current tenant.
Auto-resolve on login
When a user logs in, their session has notenantId. The resolvedDefaultId from useTenant() tells you which tenant the server recommends — typically the last-accessed tenant.
Use this to auto-switch on app mount:
TenantProvider. After the tenant list loads, it auto-switches to the resolved default if no tenant is currently selected.
Common patterns
Tenant name in header
Redirect after switch
With custom avatars per tenant
Server setup
The client-side tenant features require server-side configuration. See the server multi-tenancy guide for:- Configuring
tenant.verifyMembership,tenant.listTenants, andtenant.resolveDefault - How tenant-scoped JWTs work
- Automatic entity tenant scoping
- Endpoint reference
Next steps
Server Multi-Tenancy
Configure tenant endpoints, membership verification, and auto-resolve.
Authentication
AuthProvider, useAuth(), and session management.
Access Control
Entitlements and tenant-scoped access rules.