我怎样才能发送和JSONweb令牌在浏览器中

我怎样才能发送和JSONweb令牌在浏览器中? 我需要在用户login后发送每个禁止的页面令牌。

我有代码,一切工作正常邮递员,但是当我尝试在浏览器req.headers["authorization"]始终未定义。 我也试图res.set({'token': 'some token'}); 然后请求在下一页但仍未定义。 有很多邮差的教程,但我可以弄清楚如何在浏览器中做到这一点。 这是我的代码:

 app.post("/api/login", function(req, res) { var user = { id: 3 }; var token = jwt.sign({ user }, 'secret'); res.json({token: token}); 

});

 app.get('/api/protected', ensureToken, function(req, res) { jwt.verify(req.token, 'secret_key_goes_here', function(err, data) { if (err) { res.sendStatus(403); } else { res.json({ description: 'Protected information. Congrats!' }); } }); 

});

 function ensureToken(req, res, next) { const token = req.headers["authorization"]; console.log(token); if (typeof bearerHeader !== 'undefined') { console.log('ok'); const berarer = bearerHeader.split(" "); const bearerToken = berarer[1]; req.token = bearerToken; next(); } else { console.log('no'); res.sendStatus(403); } 

}

请任何build议。

谢谢