My code is as follows
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('/');
It prints 'pre promise'and then crash is as follows
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)
Users looks like:
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);
});
});
}
I have the same issue with everyauth 0.2.32. Looks like everyauth.Promise is not being exported and the app crashes when you try to instantiate an 'undefined' class
You can check if (Promise == 'undefined')
in recent versions of everyauth you should use following syntax:
.findOrCreateUser(function(session, accessToken, accessTokenSecret, twitterUserData) {
var promise = this.Promise();
users.findOrCreateByTwitterData(twitterUserData, promise);
return promise;
})