Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't override findOrCreateUser ? #7

Closed
felixchan opened this issue Apr 28, 2011 · 7 comments
Closed

Can't override findOrCreateUser ? #7

felixchan opened this issue Apr 28, 2011 · 7 comments

Comments

@felixchan
Copy link

Thanks for building this module, I really like! But I've ran into a prob.

This may not be a bug, as I think I'm just inexperienced.
Anyway, 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 as a field, "code".

I read the documentation, and saw that you could override findOrCreateUser. So I did that:

//Begin User Login----------------
var UserSchema = new Schema({}), User;
var Promise = everyauth.Promise;
UserSchema.plugin(mongooseAuth,{
        everymodule: {
          everyauth: {
              User: function () {
                return User;
              }   
          }   
        }   
      , facebook: {
          everyauth: {
                myHostname: settings.fb.hostname,
                appId: settings.fb.fbAppId,
                appSecret: settings.fb.fbSecret,
                scope: settings.fb.fbScope,
                entryPath: "/account/facebook/auth",
                redirectPath: '/account/prep',
                findOrCreateUser: function (sess, accessTok, accessTokExtra, fbUser) {
                    var promise = new Promise(), self = this;
                    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;
                }   
        }   
    }   
}); 
mongoose.model("User", UserSchema);
var User = mongoose.model("User")
//End User Login--------------------

I copied and pasted what was in "mongoose-auth/lib/facebook/" into my app.js. (above, you see the copied code).

Everything works, and I'm able to login/create a user!! However, the only problem is that after the redirectPath, "req.user" is undefined. "req.loggedIn" says it's true, but req.user is undefined.

@bnoguchi
Copy link
Owner

What version of mongoose-auth and everyauth are you using?

@felixchan
Copy link
Author

thanks for the response!! :)

I'm using the latest versions of mongoose-auth, everyauth, and mongoose.
I even removed the modules and npm installed agan.

@felixchan felixchan reopened this Apr 29, 2011
@bnoguchi
Copy link
Owner

Can you also send over a complete gist (https://gist.github.com) because I have not been able to re-produce the req.user === undefined result that you are getting?

@bnoguchi
Copy link
Owner

Can you copy/paste the exact versions?

@felixchan
Copy link
Author

here's the public gist : https://gist.github.com/947677

@bnoguchi
Copy link
Owner

Just fixed this. Now, in your code, just replace the Promise assignment with:

var Promise = mongooseAuth.Promise

Should work after that.

--Brian

@guiomie
Copy link

guiomie commented Sep 24, 2011

I am getting the same problem with everyauth and mongoose, what is the equivalent for my set up? (i am not using mongooseAuth)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants