【问题标题】:Express js throws Rethrow non-MySQL errorsExpress js 抛出 Rethrow 非 MySQL 错误
【发布时间】:2018-01-14 23:22:16
【问题描述】:

您好,我正在学习 express 和护照,我尝试做一个注册表单,当我尝试使用 MySQL 插入一行时,我收到了这个错误,但我的表正在正确更新。

passport.use(
    'local-signup',
    new LocalStrategy({
        usernameField : 'email',
        passwordField : 'password',
        passReqToCallback : true // allows us to pass back the entire request to the callback
    },
    function(req, email, password, first_name, done) {
      var displayName = req.body.first_name;
      // find a user whose email is the same as the forms email
      // we are checking to see if the user trying to login already exists
      dbConnection.query("SELECT * FROM users WHERE email = ?",[email], function(err, rows) {
        if (err) {
          return done(err);
        }
        if (rows.length) {
          return done(null, false, { error: 'That email is already being used.' });
        } else {
          // if there is no user with that email
          // create the user
          var salt = bcrypt.genSaltSync(10);
          var passwordHash = bcrypt.hashSync(password, salt);

          var userInfo = {
            email: email,
            first_name: displayName
          };

          var insertQuery = "INSERT INTO users ( email, password, first_name) values ('"+email+"','"+passwordHash+"','"+displayName+"')";
          console.log(insertQuery);
          dbConnection.query(insertQuery,function(err, rows) {
            userInfo.id = rows.insertId;
            console.log(rows);
            return done(null, userInfo);
          });
        }
      });
    })
  );

Error of the code in console

【问题讨论】:

    标签: mysql express passport.js


    【解决方案1】:

    去掉函数中不必要的first_name参数。

    function(req, email, password, first_name, done)
    

    '代替'

    function(req, email, password, done)
    

    【讨论】:

      猜你喜欢
      • 2021-12-20
      • 2019-06-15
      • 2016-01-11
      • 1970-01-01
      • 2017-06-16
      • 1970-01-01
      • 2023-04-03
      • 2021-12-02
      • 1970-01-01
      相关资源
      最近更新 更多