如何从jwt令牌中提取用户ID?我得到了未定义的'当我试图访问' id' “解码”中的属性'对象
我的代码 -
verifyToken: function(req, res, next) {
var token = req.body.token || req.query.token || req.headers['access-token'];
if (token) {
jwt.verify(token, config.secret, function(err, decoded) {
if (err) {
return res.json({ success: false, message: 'Failed to authencticate token' });
} else {
// I want user id here. docoded.id is giving undefined
req.user = decoded;
next();
}
});
} else {
res.status(403).send({
success: false,
message: 'No token provided'
});
}
}