Dual-Strategy Authentication
A flexible middleware that secures routes by checking httpOnly cookies first, then falling back to Bearer headers. This supports both browser sessions and mobile/API clients seamlessly.
module.exports = async function (req, res, next) {
// 1. Prioritize secure, httpOnly cookie
let token = req.cookies.token;
// 2. Fallback to Authorization Header for API clients
if (!token && req.headers.authorization?.startsWith('Bearer ')) {