我的代码如下
var express = require('express'),
everyauth = require('everyauth'),
util = require('util'),
Promise = everyauth.Promise,
users = require('./users');
everyauth.twitter
.consumerKey('')
.consumerSecret('')
.findOrCreateUser(function(session, accessToken, accessTokenSecret, twitterUserData) {
console.log('pre promise');
var promise = new Promise();
users.findOrCreateByTwitterData(twitterUserData, promise);
return promise;
})
.redirectPath('/');
它打印'pre promise'然后崩溃如下
pre promise
/.../node_modules/everyauth/lib/modules/everymodule.js:348
throw err;
^
TypeError: undefined is not a function
at Object._findOrCreateUser ( .../test.js:12:19)
at Object.exec ( .../node_modules/everyauth/lib/step.js:47:21)
at .../node_modules/everyauth/lib/stepSequence.js:26:38
at [object Object].fulfill ( .../node_modules/everyauth/lib/promise.js:42:25)
at .../node_modules/everyauth/lib/stepSequence.js:29:23
at [object Object].fulfill ( .../node_modules/everyauth/lib/promise.js:42:25)
at .../node_modules/everyauth/lib/modules/twitter.js:16:15
at passBackControl ( .../node_modules/everyauth/node_modules/oauth/lib/oauth.js:359:11)
at IncomingMessage.<anonymous> ( .../node_modules/everyauth/node_modules/oauth/lib/oauth.js:378:9)
at IncomingMessage.emit (events.js:88:20)
用户看起来像:
var cradle = require('cradle');
var c = new cradle.Connection('...', 80, {
auth:{username:'admin', password:'...'}
});
var users = c.database('users');
module.exports.findOrCreateByTwitterData = function(twitterUserData, promise) {
console.log('finding');
users.view('docs/twitterId', {key:twitterUserData.id_str}, function (err, doc) {
if (err) {
console.log('twitter error');
return;
}
if (doc) {
promise.fulfill(doc);
}
else {
var doc = {
};
}
c.database('users').save(doc, function (err, res) {
if (err) {
console.log('error with users');
return;
}
promise.fulfill(doc);
});
});
}