Multi-tenant environment variable support #27
Unanswered
joriregter
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'm happy to see that Next.js and Vercel are starting to support multitenant applications. At my office we have been building multitenant applications for quite a while, but Next.js middleware features opens up a lot of new possibilities. We've been investigating how we can leverage the middleware features for multitenant websites, without losing any other features. However, there are some features that seem quite a hassle to pick up.
Multi-tenant environment variables
Of course in a multi-tenant Next.js application environment variables are still available using the native support built into Next.js. In the template it is assumed that each tenant uses the same environment variables. However, most of the times, this is not the case, meaning each tenant requires different environment variables to be set (e.g. different database connections or different service keys).
It seems that the only option to support this right now is by adding environment variables for all possible tenants prefixed with the unique identifier of that tenant. Creating a custom getter function to resolve the correct variable based on the dynamic tenant as input would then get you the value. This would work just fine, but becomes more convoluted the more environment variables you use.
Of course, there are many ways first party support in Next.js could help out, but are there any other ideas or suggestions as to how to tackle this best (for now)?
Beta Was this translation helpful? Give feedback.
All reactions