I have this code structure:
app.post('/signin', function(req, res, next) {
passport.authenticate('local-login', function(err, user, info) {
if (err) {
// return next(err);
return res.send(401)
}
if (!user) {
return res.send(401);
}
var token = jwt.sign({ user: user}, secret.secretToken, { expiresInMinutes: 60*5 });
res.json({ token : token });
})(req, res, next);
});
Code works great if I leave the return next(err);
line commented out. So where are the benefits if I would use it in conjunction with res.send(401), it possible at all.
I read this: http://howtonode.org/control-flow-part-ii and begin to grasp what is meant, but am not there yet.