Express js抛出Rethrow非MySQL错误

时间:2017-08-07 15:24:47

标签: mysql express passport.js

你好我学习快递&护照,我试图做一个注册表,当我试图使用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

1 个答案:

答案 0 :(得分:1)

删除函数中不必要的first_name参数。

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

'代替'

function(req, email, password, done)