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!
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 :-(