[英]TypeError: callback is not a function, "node_modules\jsonwebtoken\sign.js:101:14)"
When I perform a registration action in Postman, I have the following error in the console:当我在 Postman 中执行注册操作时,控制台中出现以下错误:
Error:错误:
TypeError: callback is not a function, node_modules\jsonwebtoken\sign.js:101:14)
类型错误:回调不是 function,node_modules\jsonwebtoken\sign.js:101:14)
Problem is in this line:问题出在这一行:
const token = jwt.sign({name, email, password}, process.env.JWT_SECRET, process.env.JWT_ACCOUNT_ACTIVATION, {expiresIn: '10m'});
controllers/auth控制器/身份验证
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'});
});
};
Updated更新
When I deleted process.env.JWT_SECRET
, it works.当我删除
process.env.JWT_SECRET
时,它可以工作。 Do I have to use process.env.JWT_SECRET
?我必须使用
process.env.JWT_SECRET
吗?
Swap process.env.JWT_SECRET's position with process.env.JWT_ACCOUNT and vice versa将 process.env.JWT_SECRET 的 position 与 process.env.JWT_ACCOUNT 交换,反之亦然
jwt.sign basically accept four parameter jwt.sign 基本接受四个参数
if you change the order in that case you will get this error如果您在这种情况下更改订单,您将收到此错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.