user3265816
user3265816

Reputation: 13

Express js throws Rethrow non-MySQL errors

Hi I'm learning express & passport, i tried to do a signup form, when i tried to insert a row using MySQL, i'm getting this error but my table is updating properly.

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

Upvotes: 1

Views: 2696

Answers (1)

veeran
veeran

Reputation: 362

Remove the first_name parameter in the function which is not necessary.

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

'instead'

function(req, email, password, done)

Upvotes: 1

Related Questions