Keys / NextAuth.js
NEXTAUTH_SECRET
The random string NextAuth.js encrypts its JWT and hashes email sign-in tokens with. You generate it; no provider issues it.
- Expires
- never; you replace it
- API
- none; you generate it with
npx auth secret
Get it
Create one on next-auth.js.org/configuration/options. The steps aren't recorded yet.
Set it
NEXTAUTH_SECRET=...
next-auth v4 reads it on its own. v5 still reads it after AUTH_SECRET, the name Auth.js now prefers. Or keep it out of .env with keypin: keypin run -- npm run dev
Replace it
- Generate a new value with
npx auth secretoropenssl rand -base64 32. - Deploy it everywhere that reads
NEXTAUTH_SECRET. v4 takes one secret, so JWT sessions made with the old value stop working and people sign in again. - On v5, pass both values to the
secretoption as an array, the new one first, to keep old sessions working until they expire.
Set rotate_every on the key in keypin.toml and a rotated date on its vault item, and keypin status shows when it's due.