A PFUser Deleting Their Own Account

93 Views Asked by At

In my project I will like to allow the user to delete their own account. I have googled around for this answer but nothing comes up. I only get how to delete objects. Currently the only way I know how to do this is to manually delete the user myself in the Parse Dashboard. How do I give the users access in the app to delete themselves (their accounts)?

2

There are 2 best solutions below

0
Rashwan L On BEST ANSWER

From their documentation you can call this:

func deleteInBackground(block: PFBooleanResultBlock? = nil)

Deletes the PFObject asynchronously and executes the given callback block.

So you could do something like this:

if PFUser.currentUser() != nil {
    PFUser.currentUser()?.deleteInBackgroundWithBlock({ (deleteSuccessful, error) -> Void in
        // User deleted, log out the user
        PFUser.logOut()
    })         
}

In the given callback block you logout with PFUser.logOut().

0
dr_barto On

PFUser is a subclass if PFObject, it's built-in but apart from that it's an ordinary Parse class. So you can delete a user in the same way as you can delete any custom Parse object.