Keys / Better Auth

BETTER_AUTH_SECRET

The random string Better Auth encrypts, signs and hashes with. You generate it; no provider issues it.

Expires
never; you replace it
API
none; you generate it with openssl rand -base64 32

Get it

Create one on www.better-auth.com/docs/installation. The steps aren't recorded yet.

Set it

BETTER_AUTH_SECRET=...

better-auth reads it on its own, then AUTH_SECRET. In production it throws if neither is set. Or keep it out of .env with keypin: keypin run -- npm run dev

Replace it

  1. Generate a new value with openssl rand -base64 32. It must be at least 32 characters.
  2. Set BETTER_AUTH_SECRETS to versioned values, the new one first, such as 2:<new>,1:<old>, and keep BETTER_AUTH_SECRET as it is. Better Auth encrypts with the first and still decrypts with the rest.
  3. Session cookies are signed with the new value only, so people sign in again after you deploy.
  4. Once nothing encrypted with the old value is still needed, remove it from BETTER_AUTH_SECRETS and from BETTER_AUTH_SECRET, AUTH_SECRET and the secret option.

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