Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 无法访问';forheader&x27;初始化前_Node.js_Jwt - Fatal编程技术网

Node.js 无法访问';forheader&x27;初始化前

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

我正在尝试验证标头中的令牌,但它显示了此错误

ReferenceError:初始化之前无法访问“forheader”

错误出现在我在第一个验证方法中的命令中提到的行中

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);
        }
    })
});