title: How to pass a third argument to a callback using Bluebird.js nodeify
body: <p><a href="https://codereview.stackexchange.com/questions/51712/is-this-a-reasonable-way-to-implement-promises-in-node-js">With a little help</a> I've arrived at the following code to promisify <a href="http://passportjs.org/guide/username-password/" rel="nofollow noreferrer">a passport.js login strategy.</a></p>
  
  <pre><code>var passport = require('passport');
  var LocalStrategy = require('passport-local').Strategy;
  var Promise = require('bluebird');
  var bcrypt = require('bcrypt');
  var db = require('./db').db; //users are stored in mongo
  
  //I'm using bluebird.js for promises
  var users = Promise.promisifyAll(db.users);
  var compare = Promise.promisify(bcrypt.compare);
  
  
  // This strategy is used by passport to handle logins
  module.exports.localStrategy = new LocalStrategy(function(username, password, done) {
    users.findOneAsync({username: username}).bind({})
      .then(function(user) {
          if (!user) {
            throw new NoMatchedUserError('Incorrect username.');
            //should be equivalent to:
            // return done(null, false, {message:'something'});
          }
          this.user = user;
          return compare(password, user.password);
      })
      .then(function(isMatch) {
        if (isMatch) {
          return this.user;
          //is equivalent to:
          // return done(null, this.user);
        }
        else {
          throw { message: 'Incorrect password.' };
          //should be equivalent to:
          // return done(null, false, {message:'something else'};
        }
      })
      .nodeify(done);
  });
  </code></pre>
  
  <p>by calling <a href="https://github.com/petkaantonov/bluebird/blob/master/API.md#nodeifyfunction-callback---promise" rel="nofollow noreferrer">nodeify(done)</a> I can handle the path where passwords match but I don't know how to pass the optional third parameter out so that passport.js can use it.</p>
  
  <p>Is it possible to have the two failure (not error) paths handled?</p>
  
  <hr>
  
  <p>Update:</p>
  
  <p>As asked in the comments I created an issue on Github and this feature was (very promptly) added in Bluebird v2.0 </p>
  
  <p><a href="https://github.com/petkaantonov/bluebird/issues/219" rel="nofollow noreferrer">https://github.com/petkaantonov/bluebird/issues/219</a></p>