RFC: Improved environment detection (WIP) #6247
balazsorban44
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Background
Auth.js relies on contextual information about the environment it runs in., It needs to know if it is served from a trusted host (
AUTH_TRUST_HOST
), it needs a secret (AUTH_SECRET
) value for generating JWTs, and working with OAuth providers, etc.Auth.js is the next iteration on NextAuth.js, the library that was focused solely on Next.js/Node.js support.
The standard way of passing information in this context has been
process.env
1.Now that the ecosystem is growing and we want to support multiple frameworks and runtimes, there comes a challenge of fragmentation around environment variable handling.
Goals
We want to make it easier to handle environment variables, by detecting them automatically, so they don't need to be passed manually in code.
Proposal
Introduce a
with()
method that can wrapAuthConfig
(or can receive multiple arguments, where each argument is a provider config) and injects the values coming from the environment to the passed config to Auth.js for convenience.Example:
Before:
After:
or (still supporting any
AuthConfig
)To not interfere with existing variables, we would always assume an
AUTH_
prefix, which is already the case forAUTH_SECRET
andAUTH_TRUST_HOST
.For built-in OAuth providers, it would look like
AUTH_GITHUB_ID
andAUTH_GITHUB_SECRET
, or in the case of OIDC providers, also check forAUTH_AUTH0_ISSUER
. These variables need to be well-documented for all the providers.Cons
Environment variable reading is different from framework to framework or even from runtime to runtime, so the
with
function needs to live in the specific framework's source code, referencing a bunch of environment variables. This would be much easier if a standard existed that each framework/runtime agreed on. At the time of writing this, there is only a WinterCG proposal.Frameworks might also want to analyze variables statically, meaning we also cannot do things like
const clientId = process.env[`AUTH_${provider.id.toUpperCase()}_ID`]
, so we would need to re-generate thewith
function each time a new built-in provider is added.Footnotes
Next.js - Environment Variables ↩
https://kit.svelte.dev/docs/modules#$env-dynamic-private ↩
Beta Was this translation helpful? Give feedback.
All reactions