2017-08-07 72 views
1

嗨,我正在學習快遞&護照,我試圖做一個註冊表單,當我試圖插入一行使用MySQL,我得到這個錯誤,但我的表正在更新正確。快遞js拋出Rethrow非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

在不是必要的功能中刪除first_name的參數。

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

'而不是'

function(req, email, password, done)