I have this piece of middleware where if no token found the request responds and that is what happens but the console.log line still runs after the request responds. Why does that happen? I always thought that the res.json call would "end" the middleware. Thanks in advance.
const jwt = require("jsonwebtoken")
const config = require("../../utils/config")
const requireAuthenticated = (req, res, next) => {
const token = req.headers.authorization
if (!token) {
res.status(400).json({ error: 'Token required' })
}
console.log(jwt.verify(token, config.JWT_SECRET))
}
module.exports = requireAuthenticated