Every database row in ERP B2B Premium carries aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ency07/B2B/llms.txt
Use this file to discover all available pages before exploring further.
tenant_id UUID foreign-keyed to the tenants table. Tenant isolation is enforced at two independent layers: the application layer (tenant resolver + validateTenantAccess) and the database layer (Supabase Row Level Security policies). Either layer alone would be sufficient to block cross-tenant access; both together make a bypassed security control an explicit architectural step, not an accident.
Tenant Resolver Strategy
src/platform/tenant/tenant-resolver.ts translates a human-readable tenant_code string (e.g. "acme") into a UUID suitable for database queries. It uses a three-tier lookup with a fourth fallback:
Tier 1 — Static Map (seed tenants)
Tier 2 — Dynamic In-Memory Cache (DYNAMIC_TENANT_CACHE)
Tenants registered at runtime (beyond the two seed tenants) are stored in DYNAMIC_TENANT_CACHE after their first successful database lookup. Subsequent requests for the same tenant code return immediately from memory with no database round-trip.
Tier 3 — Database Fallback
If a tenant code is not found in either the static map or the in-memory cache, the resolver queries Supabase using the admin client:DYNAMIC_TENANT_CACHE before being returned, so only the first request for a new tenant incurs the DB round-trip.
Tier 4 — Default Fallback
If the database query returns no result (unknown tenant code, or Supabase is unavailable), the resolver falls back toNEXT_PUBLIC_DEFAULT_TENANT_CODE:
Exported API
resolveTenantIdAsync in all Server Actions — it is the authoritative path and will always return the correct UUID. Use resolveTenantId (sync) only for non-critical UI rendering where a stale or default value is acceptable and a database call is not possible.
validateStaticTenantIds() is a utility for tests. It queries the database and returns a list of collision strings if a seed UUID has been overwritten by a real tenant row — an empty array means the seed configuration is clean.
How to Add a New Tenant
-
Insert a row into the
tenantstable with a uniquetenant_code, a UUIDid, andstatus = 'Activo': - The new tenant is immediately discoverable via the Tier 3 database fallback. No code change or deployment is required.
-
To make this tenant the default for environments where
tenant_codeis absent, set: -
Optionally seed
tenant_settingsrows for branding (logo, colors, company name) so the public site renders correctly before any ERP user logs in.
Suppressing Unknown-Tenant Warnings
In CI environments and integration test suites, requests may be made with synthetic or fixture tenant codes that are intentionally not in the database. To prevent noisyconsole.warn output, set:
"true", the resolver silently falls back to the default tenant without logging. Do not set this in production — unexpected tenant codes in production are a signal of misconfiguration and should always surface as warnings.