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

  1. Generate a new value with npx auth secret or openssl rand -base64 33.
  2. On Auth.js and next-auth v5, pass both values to the secret option as an array, old first, and deploy to every instance. Every instance can now read either.
  3. 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.
  4. When sessions made with the old value have expired (30 days by default), set AUTH_SECRET to 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.

Sources, checked 2026-11-16