Express Middleware Hanging & Double Header Sent
What's Broken (Symptom)
Invalid tokens return `401` AND still call `next()` (throwing `ERR_HTTP_HEADERS_SENT`), OR valid tokens hang forever because `next()` is never called!
Expected Behavior
- When `req.headers.authorization` is missing/invalid, send `res.status(401).json(...)` and immediately `return` without calling `next()`.
- When token is valid (`"Bearer valid-jwt"`), attach `req.user` and call `next()` **exactly once**.
- Never mutate headers or send a second response after `res.headersSent` is already true.
Debugging Hints (0/2 used)
Try spotting the bug in the editor first. Need a nudge? Reveal Hint 1 anytime.
Root Cause Breakdown
Pass all 3 automated verification checks on the right to unlock the full Root Cause explanation.
Automated Bug Verification
3 Checks Ready- Missing auth sends 401 once and never calls next()Early return prevents double response / fallthrough.
- Invalid Bearer token sends 401 without calling next()Malformed token must not reach protected handler.
- Valid Bearer token attaches req.user and calls next() onceHappy path must forward request instead of hanging.
Live Sandboxed PreviewCtrl + Enter to verify
Console Output0 log(s)
No console output yet. Run Preview or Verify Bug Fix.