Production Express Auth Middleware
This middleware extracts the token from the `Authorization: Bearer <token>` header, verifies the signature against `process.env.JWT_SECRET`, checks token expiration, and attaches the decoded user payload to `req.user`.
Frequently Asked Questions
Can I store the JWT in an HttpOnly cookie instead of Bearer header?
Yes, HttpOnly SameSite=Strict cookies protect tokens from cross-site scripting (XSS) attacks in single-page applications.