Node.js 无法访问';forheader&x27;初始化前
我正在尝试验证标头中的令牌,但它显示了此错误 ReferenceError:初始化之前无法访问“forheader” 错误出现在我在第一个验证方法中的命令中提到的行中Node.js 无法访问';forheader&x27;初始化前,node.js,jwt,Node.js,Jwt,我正在尝试验证标头中的令牌,但它显示了此错误 ReferenceError:初始化之前无法访问“forheader” 错误出现在我在第一个验证方法中的命令中提到的行中 function verfiytoken(req, res, next) { const forheader = req.headers['authorization']; //verfication if (typeof forheader !== 'undefined') { //t
function verfiytoken(req, res, next) {
const forheader = req.headers['authorization'];
//verfication
if (typeof forheader !== 'undefined') {
//the app crashed here in next line and shows error.
const hed = forheader.split(' ');
const forheader = hed[1];
console.log(forheader);
req.token = forheader;
next();
} else {
res.sendStatus(403);
}
}
谢谢
router.post("/sickers/filter/test", verfiytoken, cors(), (req, res) => {
jwt.verify(req.token, (err, data) => {
if (err) console.log(err)
else {
res.json(data);
}
})
});