I'm pretty new in nodeJS and came around the following problem: I defined a Function in one of my Controllers, which I want to verify a JSON-Web-Token. I used the following function:
exports.validate = function (token, cb) {
jwt.verify(token, secretToken, cb(err, decoded));
}
But everytime I want to run it, nodeJS gives me the error, that 'err' is not defined? In the jwt-Example there's following example:
// verify a token symmetric
jwt.verify(token, 'shhhhh', function(err, decoded) {
console.log(decoded.foo)
});
So somewhere obviously I went wrong, but I don't know what. I also have no Idea what to look for... I've done some Google searches, but nothing helped me so far.
I would love to hear from you.
Regards
//EDIT: That's how I call the function:
AuthController.validate(req.headers['api-token'], function(err, decoded){
if(err){ console.log('Error: ', err);
res.status(401); next();
} else if(decoded) {
console.log('Success: ', decoded);
next();
}
})