Auth.js / NextAuth Secret Generator

Auth.js needs AUTH_SECRET (formerly NEXTAUTH_SECRET) in production. Copy a fresh 32-byte base64 secret straight into your .env.

AUTH_SECRET

Generating in your browser…

Generated on your device with the Web Crypto API. Never sent or stored.

.env line
AUTH_SECRET=""

Prefer the terminal?

  • Auth.js CLI
    npx auth secret
  • OpenSSL
    openssl rand -base64 32

How to use your AUTH_SECRET

Copy the value above and add it to .env.local for development and to your hosting provider's environment variables for production. Keep it out of source control: commit an .env.example with an empty value instead, and set the real value in your hosting provider's environment settings or a secrets manager.

Auth.js uses the secret to encrypt session tokens and sign cookies. Without it, production builds refuse to start. Changing the secret signs every user out, because existing session cookies can no longer be decrypted, so rotate it deliberately rather than on every deploy.

Is it safe to generate secrets in a browser?

Only if the secret is created locally, which is how this page works. The value comes from crypto.getRandomValues, the same cryptographically secure source browsers use for TLS keys, and it never leaves your device: there is no network request, log or analytics event that includes it.

If you prefer the command line, the commands on this page produce an equivalent secret on your own machine. Either way, use a different secret for development, staging and production, and rotate it straight away if it ever appears in a log, a screenshot or a public repository.

Frequently asked questions

What is the difference between AUTH_SECRET and NEXTAUTH_SECRET?

Auth.js v5 reads AUTH_SECRET; NextAuth v4 used NEXTAUTH_SECRET. v5 still accepts the old name. Use the one your version expects.

What happens if I change AUTH_SECRET?

Existing sessions become invalid and users have to sign in again.