
Multi-Tenancy in TanStack Start: A Simple Guide
Full Source Code View the complete repo on GitHub Multi-Tenancy in TanStack Start: Subdomain & Hostname Routing Building a SaaS usually requires identifying a tenant by their subdomain or hostname . Because TanStack Start is built on top of Nitro and Vinxi, we have powerful server-side utilities to handle this during the SSR (Server-Side Rendering) phase. Here is the goal: Two subdomains, one codebase, completely different branding. Tenant 1 with custom branding and logo. Tenant 2 with custom branding and logo. 1. Normalize the Hostname In production, you'll have tenant.com or user.saas.com . In development, you likely have localhost:3000 . This utility ensures your logic stays consistent across environments. // lib/normalizeHostname.ts export const normalizeHostname = ( hostname : string ): string => { // Handle local development subdomains like tenant.localhost:3000 if ( hostname . includes ( " localhost " )) { return hostname . replace ( " .localhost " , "" ). split ( " : " )[ 0 ] }
Continue reading on Dev.to React
Opens in a new tab




