Skip to content

[Phase 4] Wire ENABLE_FIRESTORE_TENANT_ROUTING into widget API host resolution #269

Description

@chrisvogt

Part of Phase 4: Firestore Tenant Routing in Functions. Do a planning review before starting this phase.

Goal

Activate ENABLE_FIRESTORE_TENANT_ROUTING so GET /api/widgets/:provider resolves the user from tenant_hosts Firestore data rather than the WIDGET_USER_ID_BY_HOSTNAME env map. This makes the Functions layer fully dynamic for tenant routing.

Background

The flag ENABLE_FIRESTORE_TENANT_ROUTING already exists in functions/config/backend-config.ts but is not referenced anywhere in the widget resolution path. The tenant_hosts collection is already written by the onboarding flow. This PR closes that loop.

getWidgetUserIdForHostname in functions/config/backend-paths.ts currently only consults the env map. It needs to optionally query tenant_hosts/{hostname} when the flag is enabled.

Tasks

functions/config/backend-paths.ts

  • Update getWidgetUserIdForHostname to accept a documentStore or direct Firestore reference when firestoreTenantRoutingEnabled is true
  • Look up tenant_hosts/{hostname} and return the stored uid if found
  • Fall back to env map if Firestore returns no match

functions/config/backend-config.ts

  • Set ENABLE_FIRESTORE_TENANT_ROUTING=true as the new default

functions/.env.template

  • Document ENABLE_FIRESTORE_TENANT_ROUTING with description

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendCloud Functions / Express API changesfuturePlanned but not yet scheduledtenant-routingMulti-tenant hostname and domain routing

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions