Add optional dotenvx support in Next.js for encrypted env management (Native support) #81605
harshsoni-harsh
started this conversation in
Ideas
Replies: 1 comment
-
I would be in favor of this. Currently, getting these 2 technologies to work is pretty jenky (see dotenvx/dotenvx#616 (comment)). Avoiding these issues would be really helpful. |
Beta Was this translation helpful? Give feedback.
0 replies
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.
-
Goals
Non-Goals
Background
Next.js today loads .env* files through @next/env, but it lacks:
Encryption – secrets are stored in plaintext; a stray commit or log can expose credentials.
Flexible env switching – developers end up renaming files or scripting around the limitation.
dotenvx tackles these pain points:
Per-variable encryption with a project-wide public key; private key is only needed at runtime, not in the repo.
dotenvx run -f .env.prod -- next dev style workflows for layered merges.
A rich CLI (encrypt, rotate, get, set, etc.) and IDE helpers that decrypt on-the-fly.
Proposal
Opt-in flag in next.config.js, e.g.
module.exports = {
experimental: { useDotenvx: true }
}
At startup, call dotenvx.config() (fallback to dotenv in next-env when disabled).
Ship concise docs: “Enable encrypted envs with npx dotenvx encrypt -> commit the encrypted file and public key, keep the private key in your secret store.
Beta Was this translation helpful? Give feedback.
All reactions