I am using parse.com
as backend of my application, it enables the user to login through his facebook or twitter account. Also it has the feature to link twitter/facebook to his pre-existing account.
Here is the problem:
If a user logins through his facebook
account a new PFUser
is created on the cloud.
If the same user again logins through his twitter
account another PFUser
is created on the cloud.
Now if the user wants to link his facebook
account with his twitter
account, parse.com
replies with "this twitter account is already connected to another user."
How can I merge two PFUsers
here? Can anybody please suggest me an approach to solve this issue?
Without seeing any code, it sounds like you're calling PFTwitterUtils logInWithBlock
when your trying to link a twitter account. That would be the wrong approach since it will just create a new PFUser instead of using the existring PFUser created by signing in with facebook.
What you'll want to do instead is use the PFTwitterUtils
method to link the current PFUser
with a twitter account. The Parse documentation shows the following code for doing that.
PFUser *user = [PFUser currentUser];
if (![PFTwitterUtils isLinkedWithUser:user]) {
[PFTwitterUtils linkUser:user block:^(BOOL succeeded, NSError *error) {
if ([PFTwitterUtils isLinkedWithUser:user]) {
NSLog(@"Woohoo, user logged in with Twitter!");
}
}];
}
You can do one thing which is:
when you link current user with another any Facebook/Twitter account you need to Unlink the the user at some point of time. let's say when you log out you need to check whether current user is linked with Facebook/Twitter ?
if your current user is linked with any of the other user you need to unlink so that you can again link the Facebook/Twitter user with any other user, Like this
For Facebook user :
if([PFFacebookUtils isLinkedWithUser:[PFUser currentUser]]){
[PFFacebookUtils unlinkUserInBackground:[PFUser currentUser] block:^(BOOL Success,NSError *unlinkError){
if(!unlinkError){
// User unlinked
}else{
// Erro while unlink user
}
}];
}
For Twitter user :
if([PFTwitterUtils isLinkedWithUser:[PFUser currentUser]]){
[PFTwitterUtils unlinkUserInBackground:[PFUser currentUser] block:^(BOOL Success,NSError *unlinkError){
if(!unlinkError){
// unlink user
}else{
// Error while unlink
}
}];
}
Regretfully, it seems that it is not possible to have a Facebook or Twitter account linked to more than one PFUser. Additionally, it seems that it s not possible to merge two more more PFUser entries - See Parse's answer here.
What you might want to do instead is keep the data on the PFUser table strictly for authorization purposes and keep the rest of the data in a new and dedicated Parse class (say userData, pointed to by PFUser entries).
In that sense, you'll be able to use multiple PFUser entries pointing to the same userData entry. Thus if you have a previously existing PFUser entry linked to a specific Twitter account in the Parse backend, it's best that you make the user login to that specific PFUser, and then point that entry to your previously existing userData entry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With