# 401 Unauthorized without WWW-Authenticate header

**Code:** `401` · **Category:** HTTP · **Seen on:** HTTP, REST API

The server answered 401 but didn't say which authentication scheme to use.

## Meaning

RFC 7235 requires `WWW-Authenticate` on every 401. Without it browsers can't show a Basic prompt and clients can't discover Bearer/realm details. Add the header (`Bearer realm="api"`) or use 403 where authentication isn't possible.

## Common causes

- API framework returning 401 without the header
- Custom middleware ignoring the spec
- Proxy stripping the header
- Misuse of 401 for authorisation failures
- Client can't discover the auth scheme

## Quick fix

1. Send `WWW-Authenticate: Bearer realm="api"`
2. Use 403 for authenticated but forbidden
3. Don't strip the header at the proxy

## Detailed fix by platform

### Node.js

1. `res.status(401).set("WWW-Authenticate", 'Bearer realm="api"').json({ error: "unauthorized" });`

## How to diagnose

1. **Header** — Present?
2. **Scheme** — Documented?
3. **Proxy** — Strips it?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/http/401-missing-www-authenticate)
