title: Async call within Conditional in Promise Chain Not Finishing before Progressing
body: <p>I have a conditional within my promise chain that runs an async function and prior to the async function completing it assumes that the condition was met and jumps to returning the <code>else</code> statement. It might be my lack of understanding the differences between async and promises, but I find it strange that the conditional evaluates that <code>else if(!user.validPassword(password))</code> is not met prior to the method completing. The value getting returned is <code>true</code> or <code>false</code> depending on if the password matches, but even if <code>false</code> is returned the body of that <code>else if</code> is not run.</p>
  <p>Can anyone help me understand what is off in my logic?</p>
  <p><strong>Here is the promise chain with the if conditional:</strong></p>
  <pre><code>passport.use(new passportLocal({ 
          passReqToCallback: true,
          usernameField: 'email'
      },
      function(req, email, password, done) {
          console.log('passportLocal Callled')
          console.log(email)
          console.log(password)
          User.findOne({ 
              where: {
                  email: email
              }
          }).then(function(user){
              console.log('User.findOne - Finished Query')
              if(!user){
                  console.log(&quot;User not found&quot;)
                  // User not found
                  return done(null, false, { status: &quot;error&quot;, body: 'User does not exist in the database.'});
              } else if(!user.validPassword(password)) {
                  console.log(&quot;Password is incorrect&quot;)
                  // Wrong password
                  done(null, false, { status: &quot;error&quot;, body: &quot;Incorrect Password&quot; });
              } else {
                  console.log(&quot;User found &amp; password correct&quot;)
                  // User found and password correct
                  return done(null, user, { status: &quot;success&quot;, body: &quot;You have successfully signed in!&quot; })
              }
          }).catch(function(err){
              console.log(&quot;Server error with signin&quot;)
              console.log(err)
              // Server error
              return done(null, false, { status: &quot;error&quot;, body: &quot;It looks like there was a server issue. Please try again.&quot; });
          })        
      })
  );
  </code></pre>
  <p><strong>And the if statement by itself for clarity:</strong></p>
  <pre><code>if(!user){
                  console.log(&quot;User not found&quot;)
                  // User not found
                  return done(null, false, { status: &quot;error&quot;, body: 'User does not exist in the database.'});
              } else if(!user.validPassword(password)) {
                  console.log(&quot;Password is incorrect&quot;)
                  // Wrong password
                  done(null, false, { status: &quot;error&quot;, body: &quot;Incorrect Password&quot; });
              } else {
                  console.log(&quot;User found &amp; password correct&quot;)
                  // User found and password correct
                  return done(null, user, { status: &quot;success&quot;, body: &quot;You have successfully signed in!&quot; })
              }
  </code></pre>
  <p><strong>And finally <code>user.validPassword(password)</code>:</strong></p>
  <pre><code>users.prototype.validPassword = async function(password) {
      return bcrypt.compareSync(password, this.password); // returns `true` or `false`
    }
  </code></pre>