title: Can't return data out of the bcrypt.compare() function in nodejs with promises
body: <p>I'm currently buildung an application with nodejs (10.15.2) but I'm running into some problems with the login function.</p>
  
  <p>Snippet from my "dbconnector.js" file:</p>
  
  <pre><code>login(email, password) {
      return userModel.findOne({
        email: email
      }).lean().then(function(user) {
        // return user;
        return bcrypt.compare(password, user.password, function(err, res) {
  
             if (res) {
                console.log(user); //prints the userinfo - works fine
                return user;
            }
          });
      });
  };
  </code></pre>
  
  <p>Snippet from my serve.js file:</p>
  
  <pre><code>app.post('/login', async (req, res) =&gt; {
  
      var { email, password } = req.body;
      var user = await dbconnector.login(email,password);
      console.log(user) //returns undefined
  
      if (user != false) {
        console.log("loggedin");
          const accessToken = jwt.sign({ email: user.email,  id: user.id }, key.tokenKey);
  
          res.json({
              accessToken
          });
      } else {
          res.send('Username or password incorrect');
      }
  });
  </code></pre>
  
  <p>My problem is that the <em>login()</em>-function returns undefined. However, when I change it to the following, it works perfect (just without checking the password...):</p>
  
  <pre><code>  login(email, password) {
      return userModel.findOne({
        email: email
      }).lean().then(function(user) {
      return user;
      });
  };
  </code></pre>
  
  <p>So I know something's wrong with the bcrypt / promise part but I couldn't find a solution.</p>