Answer the question
In order to leave comments, you need to log in
How is return res.json() different from res.json()?
How is return res.json() different from res.json()?
And how is return next() different from next()?
In both cases, everything works the same way.
app.post('/login', function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
if (err) return next(err);
if (!user) {
return res.status(401).json({ status: 'error', code: 'unauthorized' });
} else {
return res.json({ token: jwt.sign({id: user.id}, secret) });
}
})(req, res, next);
});
Answer the question
In order to leave comments, you need to log in
return is just the end of the function.
and
res.json({ token: jwt.sign({id: user.id}, secret) });
return;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question