我在我的 MEAN Stack webapp 中使用 Satellizer 来登录用户。satellizer 模块使用 JSON Web 令牌。
令牌创建于:
var jwt = require('jwt-simple');
function createJWT(user) {
var payload = {
sub: user._id,
user: {
displayName: user.displayName,
email: user.email,
admin: user.admin
},
iat: moment().unix(),
exp: moment().add(2, 'hours').unix()
};
return jwt.encode(payload, config.TOKEN_SECRET);
}
app.post('/auth/login', function(req, res) {
User.findOne({ email: req.body.email }, '+password', function(err, user) {
if (!user) {
return res.status(401).send({ message: 'Wrong email and/or password' });
}
user.comparePassword(req.body.password, function(err, isMatch) {
if (!isMatch) {
return res.status(401).send({ message: 'Wrong email and/or password' });
}
res.send({ token: createJWT(user) });
});
});
});
问题是稍后在函数中,我需要更新有效负载对象中的用户密钥。
这可能吗?