Saturday 22 April 2017

Need value from callback to be accessible in entire file

Relevant posts already exist but I couldn't figure out how to apply the principles to my situation.

I need the function to return the returnVal as modified within the callback (which obviously doesn't work - returns false every time).

Any ideas?

function login(user){
  var returnVal = false;
  User.findOne({username: user.username}, function (err, res){
    res.comparePassword(user.password, function(err, isMatch) {
      if (err) throw err;
      if(isMatch){
        returnVal = true;
      }
    });
  });
  return returnVal;
}

Thank you!



via Martin Stuessy

No comments:

Post a Comment