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

Facebook update support #105

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

STRML
Copy link

@STRML STRML commented May 31, 2012

Added update support for Facebook: subsequent logins will update stored access_token and fb metadata.

I noticed the FB data stored by mongoose-auth on first login quickly becomes stale. This addition to findOrCreateUser will update the stored data with new data when available.

I also added an 'isNew' field to the schema as well. This is true if and only if the user is completely fresh. We use this locally for asking the user to verify certain data, e.g. email address.

STRML and others added 3 commits March 26, 2012 19:54
Check user.fb.isNew to check if user was just created.  Useful for
email & other data verification.
Sometimes this would error out - bad connection, who knows what, and
create an additional user object for you. Bad mongoose-auth.
@STRML
Copy link
Author

STRML commented Sep 12, 2012

Using the above code simplifies the example code given for using Facebook and password login simultaneously. See the call to user.updateFBData():

findOrCreateUser: function (session, accessTok, accessTokExtra, fbUser) {
    var promise = this.Promise()
        , User = this.User()();
    User.findById(session.auth.userId, function (err, user) {
      if (err) return promise.fail(err);
      if (!user) {
        User.where('password.email', fbUser.email).findOne( function (err, user) {
          if (err) return promise.fail(err);
          if (!user) {
            User.createWithFB(fbUser, accessTok, accessTokExtra.expires, function (err, createdUser) {
              if (err) return promise.fail(err);
              return promise.fulfill(createdUser);
            });
          } else {
            user.updateFBData(fbUser, accessTok, accessTokExtra, function(err, user){
              if (err) return promise.fail(err);
              promise.fulfill(user);
            });
          }
        });
      } else {
        user.updateFBData(fbUser, accessTok, accessTokExtra, function(err, user){
          if (err) return promise.fail(err);
          promise.fulfill(user);
        });
      }
    });
  return promise; // Make sure to return the promise that promises the user
}

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

Successfully merging this pull request may close these issues.

1 participant