I use parsing in an iOS application, and there are two ways to register: using email / password or logging in to Facebook.
The problem occurs when a user logs in using their email address / password, and then logs out and tries to register using their Facebook account, which has the same email address.
I use [PFFacebookUtils logInInBackgroundWithReadPermissions:block: to register on Facebook, which creates a new user object in the Users table in Parse
Now I have two entries for the same user, and I can’t update the entry that has Facebook information with the user's email, because Parse will not allow duplicate emails
So what should be the best solution to solve this problem?
UPDATE
I used the @kRiZ solution to log in using a simple Facebook code, either by creating a new user or by linking the user to Facebook data.
- (void)loginWithFacebookWithSuccessCallback:(APISuccessCallback)successCallback andFailureCallback:(APIFailureCallback)failureCallback { // Login PFUser using Facebook NSArray *permissionsArray = @[@"public_profile", @"email"]; FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions: permissionsArray handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { failureCallback(error); } else { FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me?fields=id,first_name,last_name,email,gender" parameters:nil]; [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id fbResult, NSError *error) { if (!error) { NSString *email = result[@"email"]; User *existingUser = [self getUserByEmail:email]; if (existingUser == nil) { [self signUpNewUserWithEmail:email]; } else { // Need to set the current user to existingUser } [self linkCurrentWithAccessToken:result.token successCallback(@{RESULT:RESULT_OK}); } else { failureCallback(error); } }]; } }]; }
Now the problem is to assign [PFUser currentUser] to an existing user in case he already exists.
source share