Reputation: 1878
I'm trying to delete the image connected to the current user from the imageOne
column in Parse.com. From the user class.
PFQuery *query = [PFUser query];
[query selectKeys:@[@"imageOne"]];
[query getObjectInBackgroundWithId:[[PFUser currentUser] objectId] block:^(PFObject *object, NSError *error) {
if (!error) {
[object deleteInBackground];
}
}];
My code doesn't work and the console logs this error "User cannot be deleted unless they have been authenticated via logIn or signUp"
.
How can I fix this?
Seems like the problem comes from the fact that object (image) comes from the user class, am I right?
Upvotes: 1
Views: 3000
Reputation: 16874
Why are you doing a query for all users and then doing the delete for just the current user, that's the worst possible way to structure the query (and most likely to fail).
If the current user isn't in the first 100 returned your above code would never find a match.
This sort of query should instead be done using getObjectInBackgroundWithId:block:
, but in the case of the current user you already have the object, just do this:
[[PFUser currentUser] deleteInBackground];
If instead you just want to delete information in a column, use the following:
PFUser *currentUser = [PFUser currentUser];
[currentUser removeObjectForKey:@"imageOne"];
[currentUser saveInBackground];
Upvotes: 9