Javascript 带有jwt的标题到另一个带有节点js的页面
如果用户正确登录,我已经创建了一个post请求来发送JW令牌。标题与Auth标记一起出现,但我无法将该标记传递到其他页面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
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');
}
}
我试过邮递员工作很好