BETTER_AUTH_SECRET Generator
Generate a BETTER_AUTH_SECRET in your browser, 32 random bytes as base64 like openssl rand -base64 32, with the .env line and the wrangler command.
- Runs in your browser
Checked
01Tool
Tool
Characters
44
Entropy
256 bits
Bytes
32
Secrets appear here once the page has loaded.
openssl rand -base64 3202Guide
How it works
What Better Auth signs with it
Better Auth uses the secret to sign and encrypt what it hands the browser, such as session cookies. Anyone who has it can forge them, so keep it out of your repository and out of client code.
Why base64
The Better Auth docs suggest openssl rand -base64 32, and this preset makes the same thing: 32 random bytes written as 44 base64 characters. Switch to base64url if the value has to go into a URL.
03Questions
Questions
- How long does BETTER_AUTH_SECRET need to be?
- Better Auth asks for at least 32 characters, generated with high entropy. 32 random bytes in base64 make 44 characters.
- Is this the same as openssl rand -base64 32?
- Yes. Both take 32 bytes from a cryptographic generator and write them as base64. This page uses the browser's crypto.getRandomValues instead of OpenSSL.
- Can I rotate BETTER_AUTH_SECRET?
- Better Auth has a BETTER_AUTH_SECRETS option for rotation, so you can add a new secret without breaking what the old one signed. Read its docs before you rely on it.
- How do I set it on Cloudflare Workers?
- Run npx wrangler secret put BETTER_AUTH_SECRET and paste the value at the prompt. For local development, put the .env line in .env or .dev.vars, not both.
04Sources
Sources
Every fact on this page was read from these pages on .
- Better Auth docs, Installationbetter-auth.com/
docs/ installation - Cloudflare Workers docs, Secretsdevelopers.cloudflare.com/
workers/ configuration/ secrets/ - MDN, Crypto.getRandomValues()developer.mozilla.org/
en-US/ docs/ Web/ API/ Crypto/ getRandomValues
Found something out of date? Tell us.
Nuxter
Building a SaaS on Nuxt?
Nuxter uses nuxt-auth-utils rather than Better Auth, with email links, passwords, passkeys and social sign-in built in, so its one session secret is NUXT_SESSION_PASSWORD.