Better Auth Secret Generator
Generate a cryptographically secure BETTER_AUTH_SECRET with one click. The key is created locally in your browser with the Web Crypto API — the same strength as npx @better-auth/cli secret.
Generated locally in your browser with the Web Crypto API — nothing is ever sent to a server.
What is BETTER_AUTH_SECRET?
BETTER_AUTH_SECRET is the server-side secret Better Auth uses to sign session tokens, encrypt sensitive cookies and hash verification data. Every Better Auth project needs one — in production the library refuses to start with a missing or default value.
The secret must be a high-entropy random string that only your server knows. A weak or shared secret lets an attacker forge session cookies and sign in as any user. Generate a dedicated 32-byte secret per project and per environment, and never commit it to version control.
How to use the secret with Better Auth
1. Add the generated key to your .env file as BETTER_AUTH_SECRET:
# .env
BETTER_AUTH_SECRET=your-generated-secret
BETTER_AUTH_URL=http://localhost:30002. Better Auth picks it up from the environment automatically — or pass it explicitly via the secret option:
// lib/auth.ts
import { betterAuth } from "better-auth";
export const auth = betterAuth({
// Better Auth reads BETTER_AUTH_SECRET from the environment
// automatically — set the option only to override it.
secret: process.env.BETTER_AUTH_SECRET,
// ...database, plugins, social providers
});Generate a Better Auth secret from the command line
Prefer a terminal? The official Better Auth CLI and openssl produce the same class of 32-byte secret:
# Better Auth CLI
npx @better-auth/cli@latest secret
# or with openssl
openssl rand -base64 32Need keys for AUTH_SECRET, NEXTAUTH_SECRET or JWT signing too? Use the universal auth secret generator.
Frequently Asked Questions
How long should a BETTER_AUTH_SECRET be?
At least 32 bytes (256 bits) of randomness — the same strength that npx @better-auth/cli secret and openssl rand -base64 32 produce. This generator defaults to 32 bytes in URL-safe Base64.
What's the difference between BETTER_AUTH_SECRET and AUTH_SECRET?
BETTER_AUTH_SECRET is read by Better Auth, while AUTH_SECRET is the variable Auth.js (NextAuth v5) reads. Better Auth checks BETTER_AUTH_SECRET first and falls back to AUTH_SECRET, so either works — but a dedicated BETTER_AUTH_SECRET keeps projects that mix auth libraries unambiguous.
Is it safe to generate the secret in the browser?
Yes. This tool uses crypto.getRandomValues from the Web Crypto API — the same CSPRNG quality as openssl. The secret is generated entirely on your device and never transmitted anywhere.
What happens if I rotate BETTER_AUTH_SECRET?
All sessions and tokens signed with the old secret become invalid, so users will need to sign in again. Rotate immediately if you suspect a leak, and use a different secret for development, preview and production.
This free tool is built and maintained by NEXTY.DEV — the Next.js SaaS boilerplate that ships with Better Auth, Stripe payments and AI already wired up.