1

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?

2
  • The error tells us you cannot delete a user unless the user is logged in. Is the user logged in? Commented Aug 17, 2014 at 21:05
  • Yes, the user is logged in. Commented Aug 17, 2014 at 21:11

1 Answer 1

9

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];
Sign up to request clarification or add additional context in comments.

4 Comments

Please take a look at the updated code, does it seem better? I still get the exact same error though..
As per the error, you must use a user authenticated via logIn or signUp, you can't use one retrieved from a query. Try using the code I provided.
But in your code the whole user gets deleted, I just want the image file saved in the "imageOne" column deleted. Or am I misunderstanding you?
Your original and updated code would have also deleted the whole user if you hadn't hit the error. I will update my answer with how to delete a column value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.