简体   繁体   English

类型错误:回调不是 function,“node_modules\jsonwebtoken\sign.js:101:14)”

[英]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 基本接受四个参数

  • payload有效载荷
  • secret秘密
  • options选项
  • callback function回调 function

if you change the order in that case you will get this error如果您在这种情况下更改订单,您将收到此错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 节点js TypeError:callBack不是函数 - node js TypeError: callBack is not a function 类型错误:回调不是 function - 节点 JS - TypeError: callback is not a function - Node JS 得到一个错误 TypeError: color.charAt is not a function in C:/...../node_modules/@material-ui/core/styles/colorManipulator.js:148 - Getting a error TypeError: color.charAt is not a function in C:/...../node_modules/@material-ui/core/styles/colorManipulator.js:148 模块构建失败(来自 ./node_modules/postcss-loader/src/index.js):SyntaxError (2:14) 未知词 - Module build failed (from ./node_modules/postcss-loader/src/index.js): SyntaxError (2:14) Unknown word TypeError: str.charAt is not a function: at parse (/app/node_modules/pg-connection-string/index.js:13:11) Heroku Addons postgresql - TypeError: str.charAt is not a function: at parse (/app/node_modules/pg-connection-string/index.js:13:11) Heroku Addons postgresql 从node_modules将JS导入Vue - Import JS to Vue from node_modules 无法在 Express js 中安装 node_modules - Unable to install node_modules in Express js 〜导入scss的符号是在Angular 6中的node_modules中搜索 - ~ sign to import scss is searching inside node_modules in Angular 6 Moustrap node.js; 未捕获的TypeError:回调不是函数 - Moustrap node.js; Uncaught TypeError: callback is not a function TypeError: request.callback is not a function using Node JS and SQLServer Tedious - TypeError: request.callback is not a function using Node JS and SQLServer Tedious
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM