Keys / Auth.js
AUTH_SECRET
The random string Auth.js encrypts session cookies and 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 authjs.dev/getting-started/deployment. The steps aren't recorded yet.
Set it
AUTH_SECRET=...
Auth.js, including next-auth v5, reads it on its own. NextAuth.js v4 and Better Auth fall back to it. 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 33. - On Auth.js and
next-authv5, pass both values to thesecretoption as an array, old first, and deploy to every instance. Every instance can now read either. - Then put the new value first and deploy again. Auth.js signs new sessions with the first and still reads ones signed with the rest.
- When sessions made with the old value have expired (30 days by default), set
AUTH_SECRETto the new value and remove the old one. NextAuth.js v4 and Better Auth rotate differently; see their own pages.
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.