TypeError:无法读取undefined的属性'token'

时间:2017-09-26 14:47:37

标签: token mean-stack

我遇到此错误:TypeError:无法读取未定义的属性'token'   - 这是a link!到我的github页面

我使用firefox插件发布数据并以json格式发送数据,如:{“x-access-token”:“jashiuahf”}

这是图片enter image description here @fabio

有人可以帮我解决这个问题!!!

1 个答案:

答案 0 :(得分:0)

看起来错误来自这些行

app.use(function(req, res, next) {
console.log(req.headers['x-access-token']);
var token = req.body.token || req.body.query || req.headers['x-access-token'];
........ more code ....

我认为req.body.tokenreq.body.query不是查找身份验证或访问令牌的地方,总是尝试在请求标头中查找它。该错误是因为token不是req.body的属性,只是

var token = req.headers['x-access-token'] || '';

应该有用。

还要检查此问题:get authorization header token with node js