I am following a Node.JS tutorial that I saw the following code on it:
router.get('/checkJWTtoken', cors.corsWithOptions, (req, res) => {
passport.authenticate('jwt', {session: false}, (err, user, info) => {
if (err)
return next(err);
if (!user) {
res.statusCode = 401;
res.setHeader('Content-Type', 'application/json');
return res.json({status: 'JWT invalid!', success: false, err: info});
}
else {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
return res.json({status: 'JWT valid!', success: true, user: user});
}
}) (req, res);
});
I can't understand why did it add (req, res)
after the passport.authenticate()
in both JavaScript syntax and also specifically authenticate()
function?