在我导航到url.com/auth/github并授权github后,我得到了下面列出的错误,说我没有履行承诺,即使我已经在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('/');
(我使用的框架是Sailsjs,它应该使User.create成为可能吗?)
浏览器中的错误消息,而不是终端(终端中没有错误):
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
感谢您的帮助!
答案 0 :(得分:0)
我认为应该是
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);
}
});
不幸的是,这个库使用的promise implementation似乎缺少一些重要的功能,这些功能可以更轻松地处理promises。它甚至不是interoperable: - (