I used until"s promisify to change the verify in jwt into Synchronize"s. When I called this function and passed in an expired token, he reported an error and the program stopped going!
const util = require("util");
const verify = util.promisify(jwt.verify)
async getToken (cookieStr){
return verify(cookieStr.replace(/(^\s*)|(\s*$)/g, ""), "screct").then(function(res){
return res
}).catch(function(err){
return false
})
}
let PAYLOAD= await getToken(ctx.header.authorization)
erver error { TokenExpiredError: jwt expired
at E:\demo\node_modules\_jsonwebtoken@8.3.0@jsonwebtoken\verify.js:141:21
at getSecret (E:\demo\node_modules\_jsonwebtoken@8.3.0@jsonwebtoken\verify.js:76:14) }
jwt.verify(cookieStr, this.sign, function (err, decode) {
if (err) { // / token
rs.json({err:err})
} else {
rq.decode = decode;
console.log(decode.msg); // today is a good day
next();
}
})