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.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.TenantInfo
TenantSwitcher
A ready-made dropdown component that renders the current tenant with a menu to switch. Import from@vertz/ui-auth:
Styling
TenantSwitcher uses data-part attributes for styling:
Items have
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.