@object-ui/tenant
v3.0.3
Published
Multi-tenancy support for Object UI with tenant isolation, scoped queries, and custom branding.
Downloads
540
Readme
@object-ui/tenant
Multi-tenancy support for Object UI — tenant isolation, scoped queries, and per-tenant branding.
Features
- 🏢 TenantProvider - Context provider for tenant-aware applications
- 🔒 Tenant Isolation - Row-level and schema-level isolation strategies
- 🎨 Custom Branding - Per-tenant logos, colors, and themes via
useTenantBranding - 🛡️ TenantGuard - Protect components based on tenant status and plan
- 🔍 Scoped Queries - Automatically scope data queries to the current tenant
- 🔗 Tenant Resolver - Pluggable resolution via subdomain, path, or header
- 🎯 Type-Safe - Full TypeScript support with exported types
Installation
npm install @object-ui/tenantPeer Dependencies:
react^18.0.0 || ^19.0.0react-dom^18.0.0 || ^19.0.0
Quick Start
import { TenantProvider, useTenant, useTenantBranding } from '@object-ui/tenant';
function App() {
return (
<TenantProvider
config={{
resolutionStrategy: 'subdomain',
isolationStrategy: 'row',
}}
>
<TenantApp />
</TenantProvider>
);
}
function TenantApp() {
const { tenant } = useTenant();
const { logo, primaryColor } = useTenantBranding();
return (
<div style={{ borderColor: primaryColor }}>
<img src={logo} alt={tenant?.name} />
<h1>Welcome to {tenant?.name}</h1>
</div>
);
}API
TenantProvider
Wraps your application with tenant context:
<TenantProvider config={{ resolutionStrategy: 'subdomain', isolationStrategy: 'row' }}>
<App />
</TenantProvider>useTenant
Hook for accessing the current tenant:
const { tenant, isLoading, error } = useTenant();useTenantBranding
Hook for accessing tenant-specific branding:
const { logo, primaryColor, theme } = useTenantBranding();TenantGuard
Protects components based on tenant status or plan:
<TenantGuard requiredPlan="enterprise" fallback={<UpgradePrompt />}>
<EnterpriseFeature />
</TenantGuard>TenantScopedQuery
Automatically scopes data queries to the current tenant:
<TenantScopedQuery objectName="orders">
{({ data }) => <OrderList orders={data} />}
</TenantScopedQuery>createTenantResolver
Factory for custom tenant resolution logic:
const resolver = createTenantResolver({
strategy: 'subdomain',
fetchTenant: async (id) => api.getTenant(id),
});License
MIT
