NextAuth Secret Generator — AUTH_SECRET for Auth.js
The exact 32-byte standard-base64 value npx auth secret produces.
$ npx auth secret
What npx auth secret actually generates
The Auth.js CLI is short enough to quote: it takes crypto.getRandomValues() over 32 bytes and prints them as standard base64 — a 44-character string ending in a single =. This page reproduces it byte for byte. The one thing that matters and that most generators get wrong: it must be standard base64 (+, /, =), not the base64url this site otherwise defaults to. Auth.js feeds the value through HKDF, so a URL-safe variant technically still works — but matching the CLI is what lets you compare output and know you did it right.
AUTH_SECRET or NEXTAUTH_SECRET?
It depends on your major version, and they are not interchangeable. Auth.js v5 (the next-auth@5 / @auth/* line) reads AUTH_SECRET, and falls back to NEXTAUTH_SECRET if it is set. NextAuth v4 reads only NEXTAUTH_SECRET. If you are staring at MissingSecret: Please define a `secret` in production, this is the variable it wants — set it in your environment, not in code, and redeploy.
It is not a JWT signing secret
This is the correctness point no competing generator states, and it changes how you should think about the value. AUTH_SECRET is not an HS256 signing key. Auth.js runs it through HKDF-SHA256 to derive the key that encrypts the session cookie as an A256CBC-HS512 JWE — the token is encrypted, not merely signed. So the RFC 7518 minimum that governs a JWT HS256 secret is not what is being checked here (Auth.js enforces no length at all), but 32 random bytes is the right amount regardless. To rotate without logging everyone out, Auth.js v5 accepts an array — set AUTH_SECRET to several values and old sessions keep decrypting while new ones use the first. Better Auth uses the same shape: BETTER_AUTH_SECRET is 32 random bytes in standard base64, so the value above works there too.
How do I generate a NextAuth secret?
Run npx auth secret, or copy the value above — they produce the same thing: 32 random bytes encoded as standard base64, a 44-character string ending in one =. Set it as AUTH_SECRET in your environment (not in code) and redeploy.
MissingSecret: Please define a `secret` in production — how do I fix it?
Auth.js throws this when no secret is set in a production build. Generate one above and set it as an environment variable: AUTH_SECRET for Auth.js v5, NEXTAUTH_SECRET for NextAuth v4. It must be present at build and at runtime.
AUTH_SECRET or NEXTAUTH_SECRET?
Auth.js v5 reads AUTH_SECRET and falls back to NEXTAUTH_SECRET; NextAuth v4 reads only NEXTAUTH_SECRET. Use AUTH_SECRET on v5 and NEXTAUTH_SECRET on v4. Better Auth uses the same 32-byte standard-base64 value under BETTER_AUTH_SECRET.
Is AUTH_SECRET a JWT signing secret?
No — and this catches people. Auth.js runs it through HKDF to derive the key that encrypts the session cookie as a JWE; it does not sign an HS256 token. So the RFC 7518 length minimum for a JWT secret does not apply (Auth.js enforces no length), but 32 random bytes is the right amount anyway.
Why does the value end in an equals sign?
Because it is standard base64 of 32 bytes, and 32 is not a multiple of 3, so base64 pads the last group with one =. That trailing = is part of the value — keep it. The 33-byte option the Auth.js docs mention (openssl rand -base64 33) avoids the padding.
Nothing leaves your browser
- Don't take our word for it — turn off your wifi. Every generator on this site keeps working with the network disconnected. That's the whole proof, and it takes five seconds.
- Every value comes from
crypto.getRandomValues()— the CSPRNG built into your browser, neverMath.random(). - Generated secrets are never transmitted, logged or stored: no server-side generation, no cookies, no localStorage.
- Verify it yourself in the network tab: after loading, the page only talks to our self-hosted, cookie-less analytics — which counts page views and which generator type gets copied, never any value.
- Strict Content-Security-Policy; no third-party script origins.
All generators
- Base64 Secret Generator
- UUID Generator
- Password Generator
- Hex Secret Generator
- JWT Secret Generator
- Passphrase Generator
- SSH Key Generator (Ed25519)
- PIN Generator
- WireGuard Key Generator
- API Key Generator
- TOTP Secret Generator
- Django SECRET_KEY Generator
- Laravel APP_KEY Generator
- Flask SECRET_KEY Generator
- Rails secret_key_base Generator
- Strapi APP_KEYS Generator
- ULID Generator
- Nano ID Generator