0

After I navigate to url.com/auth/github and authorize github I get the error listed below saying I haven't fulfilled the promise even though I have done so in App.js.

App.js:

var appPath = __dirname + '/app'
    , http = require('http')
    , path = require('path')
    , fs = require('fs')
    , everyauth = require('everyauth')


everyauth.github
  .appId('xxxxxxx')
  .appSecret('xxxxxxx')
  .findOrCreateUser( function (session, accessToken, accessTokenExtra, githubUserMetadata, promise) {

      var promise = this.Promise();

      var user = {
          name: githubUserMetadata.name,
          email: githubUserMetadata.email,
          username: githubUserMetadata.login,
          firstName: name.substring(0, name.indexOf(' ')),
          githubId: githubUserMetadata.id
      };


      app.User.findOne({githubId: githubUserMetadata.id }, function(err, user) {
        if (!user) {

        User.create(user, function userCreated(err, user){
            req.session.User = user;

        });
        promise.fulfill(user);

        }

      });
      return promise;


  })
  .redirectPath('/');

(The framework I'm using is Sailsjs which should make User.create possible?)

Error message in the browser, not terminal (there is no error in terminal):

 Error: Step findOrCreateUser of `github` is promising: user ; however, the step returns
 nothing. Fix the step by returning the expected values OR by returning a Promise that
promises said values. at Step.exec (/app/node_modules/everyauth/lib/step.js:79:7) at
/app/node_modules/everyauth/lib/stepSequence.js:26:34 at Promise.fulfill
(/app/node_modules/everyauth/lib/promise.js:44:21) at
/app/node_modules/everyauth/lib/stepSequence.js:29:19 at Promise.callback
(/app/node_modules/everyauth/lib/promise.js:12:8) at
/app/node_modules/everyauth/lib/stepSequence.js:28:19 at Promise.fulfill
(/app/node_modules/everyauth/lib/promise.js:44:21) at
/app/node_modules/everyauth/lib/stepSequence.js:29:19 at Promise.fulfill
(/app/node_modules/everyauth/lib/promise.js:44:21) at
/app/node_modules/everyauth/lib/modules/github.js:50:9

Thanks for the help!

Henry Boldizsar
  • 489
  • 1
  • 8
  • 25
  • 2
    My guess is that `User.create` is asynchronous and `promise.fulfill` doesn't like to be called with nothing. – Bergi Jul 01 '14 at 19:42
  • @Bergi your guess is correct. `promise.fulfill` needs to go inside `userCreated`. – sgress454 Jul 01 '14 at 21:42

1 Answers1

0

I think it should be

app.User.findOne({githubId: githubUserMetadata.id}, function(err, user) {
  if (err) {
    promise.fail(err);
  } else if (!user) {
    User.create(user, function userCreated(err, user){
      if (err) {
        promise.fail(err);
      } else {
        req.session.User = user;
        promise.fulfill(user);
      }
    });
  } else {
    promise.fulfill(user);
  }
});

Unfortunately, the promise implementation that this library uses seems to lack some important features that would make dealing with promises so much easier. It is not even interoperable :-(

Bergi
  • 630,263
  • 148
  • 957
  • 1,375