【发布时间】:2018-07-19 21:06:48
【问题描述】:
我正在使用这种方法在成功登录后设置授权标头
router.post('/attempt', function (req, res, next) {
.....
.....
req.headers.authorization = 'JWT ' + token;
console.trace(req.headers.authorization)
调试后我可以看到它设置正确。所以我试图在同一条路线上调试相同的标头,但在设置它之前
router.post('/attempt', function (req, res, next) {
console.error(req.headers.authorization)
但它是undefined。怎么会这样?它已设置并在页面重新加载后清除?
【问题讨论】:
-
授权后没有使用中间件附加标头?
-
你的意思是
passport?但我假设你在谈论我需要的东西。现在我只是在成功登录后调用jwt.sign(user, secret, {expiresIn: 86400 * 30})。并使用res.status(200).send发送相同的令牌
标签: javascript node.js