Link anonymous parse user with email and password

372 Views Asked by At

it is possible to link a PFUser with Facebook via

[PFFacebookUtils linkUser:[PFUser currentUser] permissions:@[@"email"] block:^(BOOL succeeded, NSError *error) {
        if (error) {
            NSLog(@"error %@", error);
            // TODO smart error handling
        } else {
            // TODO to something
        }
    }];

How can I do the same with email and password. The field "authData" should change from Anonymous to something else. The function [PFAnonymousUtils isLinkedWithUser:[PFUser currentUser]] should return "NO" also logged in.

This is not working:

PFUser *user = [PFUser currentUser];
user.email = email;
user.password = password;
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (error) {
        NSLog(@"error %@", error);
        // TODO smart error handling
    } else {
        [PFUser logInWithUsernameInBackground:email password:password block:^(PFUser *user, NSError *error) {
            if (error) {
                NSLog(@"error %@", error);
            }
        }];
    }
}];
1

There are 1 best solutions below

0
On

I don't think you need to call saveInBackground on the user before logging in.

According to the parse docs:

You can convert an anonymous user into a regular user by setting the username and password, then calling signUp, or by logging in or linking with a service like Facebook or Twitter.

So after setting the email and password, try calling signUp