Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

NextAuth logs NO_SECRET, or throws it in production

Error[next-auth][warn][NO_SECRET]

Short answer

NextAuth needs a secret to encrypt its JWT and hash tokens. In development it falls back to a generated value and only warns. In production there is no default, so the error is real. Generate a random string, set NEXTAUTH_SECRET (or AUTH_SECRET) on the server, and restart the app.

  • Applies to next-auth 4, Next.js 15, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether the process that runs your app actually has the variable. Print only whether it is set, never the value.

    node -e "console.log(Boolean(process.env.NEXTAUTH_SECRET || process.env.AUTH_SECRET))"
  2. 2Match what you see, then jump to its fix

    1. 1NO_SECRET warning in development, an error in productionNo secret is configured at allFix
    2. 2Works with next dev, fails after deploy with the secret errorThe secret is set locally but not on the production serverFix

What does the error look like?

  • [next-auth][warn][NO_SECRET]
  • In production, we expect you to define a secret property in your configuration

Cause 1 of 2

No secret is configured at all

1Check

Look for NEXTAUTH_SECRET or AUTH_SECRET in your env files and for a secret option in the NextAuth config.

grep -n "NEXTAUTH_SECRET\|AUTH_SECRET\|secret:" .env* app pages lib 2>/dev/null

2Fix

Generate a random value and put it in .env.local. AUTH_SECRET is accepted as an alias for NEXTAUTH_SECRET.

openssl rand -base64 32
# .env.local
NEXTAUTH_SECRET=paste-the-generated-value-here

3Verify

Restart the dev server; the warning should disappear.

npm run dev

Confirmed by next-auth.js.org

Did this fix it?

Cause 2 of 2

The secret is set locally but not on the production server

1Check

.env.local is for your machine. The deployed process needs the variable in its own environment, and Next.js reads .env files from the project root, not from src/.

ls -a | grep "^.env"
ls src 2>/dev/null | grep "^.env"

2Fix

Add NEXTAUTH_SECRET to the environment of the service that runs the app (your host's env settings, or the process manager), then restart it.

NEXTAUTH_SECRET=paste-the-generated-value-here npm run start

3Verify

Sign in on the deployed site and watch the logs stay clean.

npm run start

Confirmed by nextjs.org

Did this fix it?

How do I stop it coming back?

  • Add NEXTAUTH_SECRET to the deploy checklist and to your host's env settings.
  • Use a different secret per environment and never commit it.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.