Search code examples
swiftparse-platformpfuser

A PFUser Deleting Their Own Account


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)?


Solution

  • 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().