ios - How to merge a user signed up by facebook with an exising user signed up with the same email -
i using parse in ios app , there 2 ways of signup, either using email/password or facebook login.
the problem happen when user sign using email/password logout , try sign using facebook account have same email.
i using [pffacebookutils logininbackgroundwithreadpermissions:block:
signup facebook creates new user object in users
table in parse
now have 2 records same user , can not update record has facebook information user email because parse not allow duplicate emails
so should best solution solve problem?
update
i have used @kriz solution login using plain facebook code either create new user or link user 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 set current user existinguser } [self linkcurrentwithaccesstoken:result.token successcallback(@{result:result_ok}); } else { failurecallback(error); } }]; } }]; }
now problem assign [pfuser currentuser] existing user in case exists
you can try linking new facebook user existing user on parse using [pffacebookutils linkuserinbackground:*...
methods.
if (![pffacebookutils islinkedwithuser:user]) { [pffacebookutils linkuserinbackground:user withreadpermissions:nil block:^(bool succeeded, nserror *error) { if (succeeded) { nslog(@"woohoo, user linked facebook!"); } }]; }
see parse documentation on linking.
- login via facebook (do not save user yet)
- query user table user having same email new fb user
- if found, link, else, save new user.
update:
linking method fb access token:
[pffacebookutils linkuserinbackground:user withaccesstoken:accesstoken block:^(bool succeeded, nserror *error) { if (succeeded) { nslog(@"woohoo, user linked facebook!"); } }];
Comments
Post a Comment