Attempts to verify a jwt (that was created using the same package result in a strange error that i cant decipher. Any help/insight into the matter would be much appreciated.
const jwt = require("jsonwebtoken");
const config = require("../config/index.js");
module.exports = {
jwtLogin: function(req, res, next){
"use strict";
const token = req.headers.authorization || req.headers.Authorization;
if (token){
const decoded= jwt.verify(token, config.secret);
console.log(decoded);
next();
}else{
return res.status(403).send({
success: false,
message: "No token provided"
});
}
}
};
The error in question:
Error
at Object.module.exports [as verify] (.../node_modules/jsonwebtoken/verify.js:97:17)
at jwtLogin (points to the line where verify is used)
Hello sir, let's try console.log in your jwt.verify'scallback
jwt.verify(token, config.secret', function(err, decoded) {
if(err){
console.log(err)
}else{
console.log(decoded)
}
})
Sorry for the extended leave. As requested I added the callback function and decided to take a screenshot
https://www.dropbox.com/s/4xwdyf8knft2mtz/screenshot.37.jpg?dl=0
In short
error: { Error
at Object.module.exports [as verify] (/home/utibe/Desktop/server_projects/api/node_modules/jsonwebtoken/verify.js:97:17)
at jwtLogin (/home/utibe/Desktop/server_projects/api/controllers/authentication.js:171:32)
Note: i also ensured that the request for the secret is fullfilled. I've deleted node_modules a few times and started anew, and it seems to have had no effect.
This is the error raised: https://github.com/auth0/node-jsonwebtoken/blob/master/verify.js#L97
You can try in https://jwt.io to with one token and the secret you provide to the verify function, in case something funny is happening with the token or your secret.
BTW when you don't provide a callback the errors are raised via throw.
Thanks!
Most helpful comment
This is the error raised: https://github.com/auth0/node-jsonwebtoken/blob/master/verify.js#L97
You can try in https://jwt.io to with one token and the secret you provide to the
verifyfunction, in case something funny is happening with the token or your secret.BTW when you don't provide a callback the errors are raised via
throw.