Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.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
Javascript 带有jwt的标题到另一个带有节点js的页面_Javascript_Node.js_Express_Jwt - Fatal编程技术网

Javascript 带有jwt的标题到另一个带有节点js的页面

Javascript 带有jwt的标题到另一个带有节点js的页面,javascript,node.js,express,jwt,Javascript,Node.js,Express,Jwt,如果用户正确登录,我已经创建了一个post请求来发送JW令牌。标题与Auth标记一起出现,但我无法将该标记传递到其他页面 router.post('/login',async(req,res)=>{ const {error} = logvali(req.body); if(error) return res.status(400).send(error.details[0].message); //check if the email exist

如果用户正确登录,我已经创建了一个post请求来发送JW令牌。标题与Auth标记一起出现,但我无法将该标记传递到其他页面

router.post('/login',async(req,res)=>{
       const {error} = logvali(req.body);
       if(error) return res.status(400).send(error.details[0].message);
       //check if the email exist
       const user = await User.findOne({email: req.body.email});
       if(!user) return res.status(400).send('Email is Wrong');
       //password  is correct
       const vapass = await bcrypt.compare(req.body.password , user.password);
       if(!vapass) return res.status(400).send('Password is Wrong');

       const token =jwt.sign({_id: user._id},process.env.TOK);
       res.header('authtok',token).send(token);


       // i want send the jwt to dashboard page
   });
我的令牌验证器

const jwt = require('jsonwebtoken');

module.exports = function (req,res,next){
const token = req.header('authtok');
if(!token) return res.status(401).send('Access Denied');

try{
    const verify = jwt.verify(token,process.env.TOK);
    req.user = verify;
    next();
}catch(err){
    res.status(400).send('Invalid Token');
}
}
我试过邮递员工作很好