Skip to content

Commit 62fe536

Browse files
authored
fix: resolve demo frontend to real tenant instead of hardcoded dev-tenant (#1245)
* fix: use header-based tenant routing in demo mode The demo frontend was routing all API calls to non-existent tenant subdomains (e.g. dev-tenant.demo.meridianhub.cloud), causing 503 errors on every request. Two changes: - transport.ts: skip subdomain routing when VITE_DEMO_MODE is set, use X-Tenant-Slug header instead (same as dev mode) - App.tsx: DevTenantAutoSelector now queries real tenants from the API instead of hardcoding a non-existent 'dev-tenant' slug * fix: revert transport change, backend requires LOCAL_DEV_MODE for header routing The gateway only reads X-Tenant-Slug when LOCAL_DEV_MODE=true (which is false on demo). Subdomain routing works correctly since Cloudflare wildcard DNS and Caddy both handle *.demo.meridianhub.cloud. The sole issue was the hardcoded non-existent tenant slug in DevTenantAutoSelector. --------- Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>
1 parent e5ed7c3 commit 62fe536

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

frontend/src/App.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { queryClient } from '@/lib/query-client'
66
import { PageErrorBoundary } from '@/components/error-boundary'
77
import { AuthProvider, useAuth } from '@/contexts/auth-context'
88
import { TenantProvider, useTenantContext } from '@/contexts/tenant-context'
9+
import { useTenants } from '@/hooks/use-tenants'
910
import { ApiClientProvider } from '@/api/context'
1011
import { ProtectedRoute, PlatformOnlyRoute } from '@/components/routing'
1112
import { AppShell } from '@/components/layout/app-shell'
@@ -228,17 +229,22 @@ function ApiClientBridge({ children }: { children: ReactNode }) {
228229
}
229230

230231
/**
231-
* In dev mode, auto-select the seeded dev tenant for platform admins
232+
* In dev/demo mode, auto-select the first real tenant for platform admins
232233
* so pages show data immediately after login.
233234
*/
234235
function DevTenantAutoSelector() {
235236
const { isPlatformAdmin, currentTenant, switchTenant } = useTenantContext()
237+
const { data: tenants } = useTenants()
236238

237239
useEffect(() => {
238-
if (isPlatformAdmin && !currentTenant) {
239-
switchTenant({ id: 'dev_tenant', slug: 'dev-tenant', name: 'Dev Tenant' })
240+
if (isPlatformAdmin && !currentTenant && tenants?.length) {
241+
// Pick the first tenant that has a slug (skip system tenants without one)
242+
const tenant = tenants.find((t) => t.slug) ?? tenants[0]
243+
if (tenant) {
244+
switchTenant({ id: tenant.tenantId, slug: tenant.slug, name: tenant.displayName })
245+
}
240246
}
241-
}, [isPlatformAdmin, currentTenant, switchTenant])
247+
}, [isPlatformAdmin, currentTenant, tenants, switchTenant])
242248

243249
return null
244250
}

0 commit comments

Comments
 (0)