Single-secret authentication configuration
A standard deployment needs one stable value for protecting authentication state.
Auth.js · Pipe
secret is the Auth.js configuration value used to hash tokens, sign cookies, and generate cryptographic keys. Provide a random string or an ordered array to support secret rotation.
Auth.js uses the secret to hash tokens, sign cookies, and derive cryptographic keys. You can supply one secret or an ordered array: the first secret able to decrypt an existing JWT is selected, while the first array entry protects newly created sessions.
secret?: string | string[]| Name | Type | Description |
|---|---|---|
secret | string | string[] | A random string, or an array of secrets used for token hashing, cookie signing, cryptographic keys, and JWT decryption. |
secret configuration accepts either one string or an array of strings.AUTH_SECRET.AUTH_SECRET is the only one documented as strictly required.import NextAuth from "next-auth"
export const { handlers, auth } = NextAuth({
providers: [],
secret: process.env.AUTH_SECRET,
})Set AUTH_SECRET in the environment, then pass it explicitly to the Auth.js configuration.
A standard deployment needs one stable value for protecting authentication state.
A team must replace a compromised or aging secret without invalidating every existing session at once.
A deployment wants JWT encryption enabled through conventional environment configuration.
The secret is used to hash tokens, sign cookies, and generate cryptographic keys. Auth.js also uses it for JWT encryption by default.
Follow-up: How can secrets be rotated without immediately invalidating sessions? Supply an array with the newest secret first; Auth.js tries the entries for decryption and uses the first entry for new sessions.
secret option accept?The configuration type is string | string[]. A single string is sufficient for normal operation, while an array supports key rotation.
Follow-up: What ordering is required during rotation? Put the newer secret at index zero so newly issued sessions use it.
The AUTH_SECRET environment variable is the conventional deployment setting, and the CLI can generate a random value with npx auth secret. The deployment documentation recommends a cryptographically secure random string of at least 32 characters.
Follow-up: Why prefer environment configuration? It keeps the secret outside source code and allows deployment-specific values.
AUTH_SECRETAuthConfigJWTMissingSecretnpx auth secret