We’re running a database-per-customer setup. On a high level these will be kinda similar.
Firstly you will need a way to get the customers location. I assume it has to be saved somewhere. You could save it within your user object and return it in your auth JWT token for quick access. Alternatively you could determine it from a subdomain, e.g. us.myapp.com or eu.myapp.com.
If you have a Vercel deployment in multi region (EU and US) you can also use VERCEL_REGION for determining the location. (Feature request: region based env var overwrite 🙂 )
Personally I would let the user select eu/us in the onboarding and save it on the user object e.g. with your auth provider and use this as a source to determine the users location.
Secondly you need to route to the correct environment vars based on the obtained location. Initialize your supabase client or whatever APIs you have with a different env var depending on the location. E.g. SUPABASE_US_DB_URL or SUPABASE_EU_DB_URL.
It will look roughly like this:
