Shashika Shashika - 3 months ago 14
Node.js Question

Unhandled Rejection - passport login app node js

I'm creating

nodejs
login app and using
passport
js for authentication. I use a local mysql database and use
sequelize
as ORM library.

In my user model, I have created to get the user by username.

module.exports.findUserByUsername = function(username, callback){
User.findOne({ where: {username: username} }).then(function(user) {
var userObj = user.get({plain:true});
callback(userObj);
})
};


In router file

passport.use('login', new LocalStrategy(
function (username, password, done) {

User.findUserByUsername(username, function (err, user) {
if(err) {
throw err;
}
console.log(user);
})
}
));


I'm getting an error
Unhandled rejection (<{object_values...>, no stack trace)


How can I solve this issue?

Answer

You need to change callback calling like this :

callback(null, userObj);
Comments