我正在使用 jwt 创建令牌,但是当我通过邮递员登录时,我从控制台收到错误“错误:secretOrPrivateKey 必须有一个值”。我附上了我的登录代码。请任何可以帮助我的人
exports.login = (req, res, next) => {
User.findOne({
where: {
email: req.body.email
}
})
.then(user => {
if (!user) {
return res.status(401).json({
message:
"Auth failed!! either the account does't exist or you entered a wrong account"
});
}
bcrypt.compare(req.body.password, user.password, (err, result) => {
if (err) {
return res.status(401).json({
message: "Auth failed",
token: token
});
}
if (result) {
const token = jwt.sign(
{
email: user.email,
password: user.id
},
process.env.JWT_KEY,
{
expiresIn: "1h"
}
);
res.status(200).json({ …Run Code Online (Sandbox Code Playgroud)