Created
May 10, 2012 14:50
-
-
Save davisford/2653658 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in models/user.js | |
var mongoose = require('mongoose'); | |
var Schema = mongoose.Schema | |
, ObjectId = mongoose.SchemaTypes.ObjectId | |
// example model | |
var UserSchema = new Schema({ | |
email: { type: String, unique: true, index: true } | |
}); | |
// more statics and virtuals here | |
var User = mongoose.model('User', UserSchema); | |
module.exports.User = User; | |
/* -------------------------------- */ | |
// in app/oauth.js | |
var mongoose = require('mongoose') | |
, User = require('./models/user').User | |
, everyauth = require('everyauth') | |
, mongooseAuth = require('mongoose-auth') | |
UserSchema.plugin(mongooseAuth, { | |
everymodule: { | |
everyauth: function() { | |
return User; // maybe I should be doing return new User() here? | |
} | |
}, | |
google: { | |
everyauth: { | |
findOrCreateUser: function (session, token, secret, googleUser) { | |
var promise = this.Promise() | |
User.findById(session.userId, function (err, user) { | |
if (err) return promise.fail(err); | |
if (!user) { | |
User.where('email', googleUser.email).findOne( function (err, user) { | |
/*** PROBLEM IS HERE ***/ | |
user.google <= undefined | |
user._doc.google => OK | |
} | |
} | |
} | |
}) | |
etc. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment