Parse-server, PFFacebookUtils overwrites username

108 Views Asked by At

So a PFUser will log in the traditional way, using an email and password. When they sign up, I set the userName to be equal to the email address. When a user signs in, they use their email.

This was working great until I added a "connect to facebook" button where I call the following:

[PFFacebookUtils linkUserInBackground:[PFUser currentUser] withReadPermissions:@[@"public_profile", @"user_friends"] block:^(BOOL succeeded, NSError *error) {
                if (succeeded) {
                    NSLog(@"Woohoo, user is linked with Facebook!");

                    [self.tableView reloadData];
                }
            }];

The problem is, when this succeeds, my username has changed to a long string of random characters. Which means if I log out, I can no longer log back in because the email no longer matches the username.

I am using parse-server on Heroku. I won't post any cloud code because this didn't start happening until I implemented Facebook oauth.

1

There are 1 best solutions below

0
On

You have to query for the user using their email. Once you've returned the user object get the username by using user.username. Once you have their username you can log them in with loginWithUsernameInBackground. It seems like the long way around an easy thing but that's how you do it.