开发者

Everyauth, first login works, second fails

Using everyauth, the first time a user login, a profile is added to my mongodb via mongoose and the session works well. The second time a user tries to login, the server crashes with the following error:

/mnt/ws/users/guiomie/70543/node_modules/everyauth/lib/modules/e开发者_StackOverflow社区verymodule.js:352 throw err;

^ TypeError: Cannot read property 'id' of undefined at Object._addToSession (/mnt/ws/users/guiomie/70543/node_modules/everyauth/lib/modules/oauth2.js:195:46) at Object.exec (/mnt/ws/users/guiomie/70543/node_modules/everyauth/lib/step.js:48:21) at /mnt/ws/users/guiomie/70543/node_modules/everyauth/lib/stepSequence.js:19:38 at [object Object].fulfill (/mnt/ws/users/guiomie/70543/node_modules/everyauth/lib/promise.js:42:25) at /mnt/ws/users/guiomie/70543/node_modules/everyauth/lib/stepSequence.js:22:23 at [object Object].callback (/mnt/ws/users/guiomie/70543/node_modules/everyauth/lib/promise.js:13:12) at /mnt/ws/users/guiomie/70543/node_modules/everyauth/lib/stepSequence.js:21:23 at [object Object].fulfill (/mnt/ws/users/guiomie/70543/node_modules/everyauth/lib/promise.js:42:25) at /mnt/ws/users/guiomie/70543/node_modules/everyauth/lib/stepSequence.js:22:23 at [object Object].fulfill (/mnt/ws/users/guiomie/70543/node_modules/everyauth/lib/promise.js:42:25)

The following is my code:

.findOrCreateUser( function (session, accessToken, accessTokExtra, fbUserMetadata) {
//Verifies if user in database already
try{
var id = fbUserMetadata.id;
var promise = this.Promise();
User.findOne({ fbid: id}, function(err, result) {
var user;
if(!result) {
user = new User();
user.fbid = id;
user.firstName = fbUserMetadata.first_name;
user.lastName = fbUserMetadata.last_name;
user.save();
} else {
user = result.doc;
}
promise.fulfill(user);
});
return promise;
}
catch(err){
console.log(err);

}
})

I use mongoose and express.


Untested, but from looking at your code, it looks like you need to change this line:

user = result.doc;

to this:

user = result;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜