当我在 Postman 中执行注册操作时,控制台中出现以下错误:
错误:
TypeError: 回调不是函数,node_modules\jsonwebtoken\sign.js:101:14)
问题出在这一行:
const token = jwt.sign({name, email, password}, process.env.JWT_SECRET, process.env.JWT_ACCOUNT_ACTIVATION, {expiresIn: '10m'});
控制器/认证
const User = require('../models/user');
const jwt = require('jsonwebtoken');
exports.signup = (req, res) => {
const {name, email, password} = req.body;
User.findOne({email}).exec((err, user) => {
if (user) {
return res.status(400).json({
error: "Email is taken"
})
}
const token = jwt.sign({name, email, password}, process.env.JWT_SECRET, process.env.JWT_ACCOUNT_ACTIVATION, {expiresIn: '10m'});
});
};
更新
当我删除process.env.JWT_SECRET时,它可以工作。我必须使用process.env.JWT_SECRET吗?
米琪卡哇伊
慕桂英4014372
相关分类