diff --git a/Parse/PFUser.m b/Parse/PFUser.m index 59898d9d4..4c1eef830 100644 --- a/Parse/PFUser.m +++ b/Parse/PFUser.m @@ -878,14 +878,19 @@ - (BFTask *)linkWithAuthTypeInBackground:(NSString *)authType authData:(NSDictio return [[self saveAsync:nil] continueAsyncWithBlock:^id(BFTask *task) { if (task.result) { [self synchronizeAuthDataWithAuthType:authType]; - } else { - @synchronized (self.lock) { - [self.authData removeObjectForKey:authType]; - [self.linkedServiceNames removeObject:authType]; - [self restoreAnonymity:oldAnonymousData]; - } + return task; + } + + @synchronized (self.lock) { + [self.authData removeObjectForKey:authType]; + [self.linkedServiceNames removeObject:authType]; + [self restoreAnonymity:oldAnonymousData]; } - return task; + // Save the user to disk in case of failure, since we want the latest succeeded data persistent. + PFCurrentUserController *controller = [[self class] currentUserController]; + return [[controller saveCurrentObjectAsync:self] continueWithBlock:^id(BFTask *_) { + return task; // Roll-forward the result of a save to network, not local save. + }]; }]; }]; }];