【发布时间】:2019-05-22 16:14:28
【问题描述】:
在我的用户控制器中,我创建了一个令牌,当他登录到我的应用程序时,我将在其中保存该用户的 ID。
exports.findOne = (req, res) => {
User.findOne({
where: {
login: req.body.login,
},
})
.then(user => {
if (user) {
if (bcrypt.compareSync(req.body.password, user.password)) {
const token = jwt.sign(
{
id: user.id, // this is the id I need.
},
env.SECRET_KEY,
{
expiresIn: 129600,
},
);
return res.status(200).json({
message: 'Auth successful',
token,
});
}
...
}
})
.catch(err => {
res.status(400).json({ error: err });
});
};
现在在另一个控制器中,我想读取这个 id 并将其用于我的目的。我怎样才能得到它?
const loginId = '?'; // here I want to give it to id
Bill.update(
{
available_funds: available_funds - amountMoney,
},
{ where: { id_owner: loginId } },
).then(() => {
res.status(200).send(`ok`);
});
【问题讨论】:
标签: javascript node.js jwt