NextAuth / Auth.js: [next-auth][error][NO_SECRET] Please define a `secret` in production / MissingSecret
Auth.js needs a secret (NEXTAUTH_SECRET / AUTH_SECRET) in production to sign and encrypt tokens/cookies.
Please define a `secret` in production Meaning
Locally it may use a default, but production builds fail or sessions break without it. Changing the secret invalidates existing sessions (JWEDecryptionFailed).
Common causes
- NEXTAUTH_SECRET/AUTH_SECRET not set in the hosting environment
- Variable named for the wrong version (v4 vs v5)
- Secret changed between deployments/instances
⚡ Quick fix
- Generate one (npx auth secret / openssl rand -base64 32) and set it in env
- Use AUTH_SECRET for Auth.js v5
- Keep the same secret across instances
Detailed fix by platform
Shell
- bash
npx auth secret # or openssl rand -base64 32
How to diagnose
- Env — Variable present at runtime?
- Version — next-auth v4 or v5?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Authentication
- disallowed_useragent Google OAuth: Error 403: disallowed_useragent (sign-in from an embedded WebView)
- invalid_token invalid_token: The access token is invalid (JsonWebTokenError: invalid signature / jwt malformed)
- Access blocked: has not completed the Google verification process Google OAuth: Error 403: access_denied — The developer hasn't given you access to this app / has not completed the Google verification process
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 13 Oct 2026