# NextAuth / Auth.js: [next-auth][error][NO_SECRET] Please define a `secret` in production / MissingSecret

**Code:** `NO_SECRET` · **Category:** Authentication · **Seen on:** REST API

Auth.js needs a secret (NEXTAUTH_SECRET / AUTH_SECRET) in production to sign and encrypt tokens/cookies.

## Meaning

Locally it may use a default, but production builds fail or sessions break without it. Changing the secret invalidates existing sessions (JWEDecryptionFailed).

## Common causes

- NEXTAUTH_SECRET/AUTH_SECRET not set in the hosting environment
- Variable named for the wrong version (v4 vs v5)
- Secret changed between deployments/instances

## Quick fix

1. Generate one (npx auth secret / openssl rand -base64 32) and set it in env
2. Use AUTH_SECRET for Auth.js v5
3. Keep the same secret across instances

## Detailed fix by platform

### Shell

1. 

```bash
npx auth secret
# or
openssl rand -base64 32
```


## How to diagnose

1. **Env** — Variable present at runtime?
2. **Version** — next-auth v4 or v5?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/auth/nextauth-no-secret)
