Wednesday, 2 August 2017

PassportJS - Keep getting 502 gateway error when logging into my website

FROM PASSPORTJS DOCSpassport.use(new LocalStrategy( function(username, password, done) { User.findOne({ username: username }, function (err, user) { if (err) { return done(err); } if (!user) { return done(null, false, { message: 'Incorrect username.' }); } if (!user.validPassword(password)) { return done(null, false, { message: 'Incorrect password.' }); } return done(null, user); }); } )); CHANGED THE USER.FINDONE TO CONNECTION.QUERY FOR MYSQLWhen I login no error shows in my console nothing gets console.log. But the website keeps on loading and loading until it finally reaches a 502 gateway error. I think it's something wrong with the connection.query.passport.use(new LocalStrategy( function(username, password, done) { connection.query('SELECT * FROM users WHERE username = ?', [username]), function (err, user) { console.log('first'); if (err) { console.log(err + 'first'); return done(err); } console.log('second'); if (!user) { console.log('incorrect username'); return done(null, false, { message: 'Incorrect username.' }); } console.log('third'); if (!user.validPassword(password)) { console.log('incorrect password'); return done(null, false, { message: 'Incorrect password.' }); } console.log('fourth'); res.render('/secret'); console.log('fifth'); return done(null, user); }; } ))

Submitted August 03, 2017 at 03:06AM by Vraz_

No comments:

Post a Comment