AI tools consistently misconfigure environment variables. Here's what to audit before deploying.
Environment variable handling in AI-generated Next.js projects has a predictable set of issues. Hardcoded values that should be env vars. Mix of `process.env.KEY` and direct string literals for the same service in different parts of the codebase. And most critically, `NEXT_PUBLIC_` prefixes on variables that should be server-side only.
The `NEXT_PUBLIC_` issue is the one worth flagging in every review. That prefix causes the variable to be inlined into the client bundle at build time. There's no runtime override. If a secret ends up there, rotating the key and redeploying is the only fix, and any version of the bundle with the old key is already in CDN caches and browser caches.
Standard checks I run: grep for `NEXT_PUBLIC_` and verify each one is intentionally public. Check that `.env` is in `.gitignore` with a committed `.env.example`. Confirm prod has different key values from dev.
What does your env var review process look like for new projects?