Right now I'm using mongoose-auth's Facebook Connect. Everything works fine, and users are being created/logged in through my mongodb server.
However, I want to over-ride findOrCreateUsers, because I want to assign each new user a random "code" upon signup, and put it inside their db.users profile.
So I looked into the mongoose-auth/lib/facebook
, and I copied those 3 facebook module files into my own directory [everyauth.js, index.js, schema.js]. To run a simple test, I basically included my own everyauth.js from my directory, and used its findOrCreateUsers method instead of the default one.
It works, but there is one error. After logging in/creating the user, req.user
is undefined. (req.loggedIn
shows True, yay!)
I know this is a new library, but if you've used it (or know a lot about Node.js), I'd really appreciate it if you could help me. I'm on #node.js on irc.freenode.net. Nickname is "xeodox". If you could help me I'd really appreciate it!!
I overrode findOrCreateUser by doing this to the facebook module in my app.js:
findOrCreateUser: function (sess, accessTok, accessTokExtra, fbUser) {
var promise = new Promise()
开发者_StackOverflow社区, self = this;
// TODO Check user in session or request helper first
// e.g., req.user or sess.auth.userId
this.User()().findOne({'fb.id': fbUser.id}, function (err, foundUser) {
if (foundUser)
return promise.fulfill(foundUser);
self.User()().createWithFB(fbUser, accessTok, accessTokExtra.expires, function (err, createdUser) {
return promise.fulfill(createdUser);
});
});
return promise;
}
No need to copy those files into your own directory. Just do the following in your mongoose-auth configuration:
facebook: {
everyauth: {
myHostname: 'http://localhost:3000'
, appId: 'YOUR APP ID HERE'
, appSecret: 'YOUR APP SECRET HERE'
, redirectPath: '/home'
, findOrCreateUser: function (session, accessToken, fbUserMetadata) {
}
}
}
For help on the undefined req.user
, file an issue on github with a link to a self-contained gist to re-create the issue, and I can help you out.
精彩评论