https://github.com/hwz/chirp/blob/master/module-5/completed/routes/api.js
function isAuthenticated (req, res, next) {
// if user is authenticated in the session, call the next() to call the next request handler
// Passport adds this method to request object. A middleware is allowed to add properties to
// request and response objects
//allow all get request methods
if(req.method === "GET"){
return next();
}
if (req.isAuthenticated()){
return next();
}
// if the user is not authenticated then redirect him to the login page
return res.redirect('/#login');
};
Why does the author do return next()
instead of next()
? I know next()
is to let the flow jump to next middleware or function, but why it needs a return
for next()
above?