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
- Generate a new value with
openssl rand -base64 32. It must be at least 32 characters. - Set
BETTER_AUTH_SECRETSto versioned values, the new one first, such as2:<new>,1:<old>, and keepBETTER_AUTH_SECRETas it is. Better Auth encrypts with the first and still decrypts with the rest. - Session cookies are signed with the new value only, so people sign in again after you deploy.
- Once nothing encrypted with the old value is still needed, remove it from
BETTER_AUTH_SECRETSand fromBETTER_AUTH_SECRET,AUTH_SECRETand thesecretoption.
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.