Delete user account
Empowering users to delete their account can improve trust and transparency. You can programmatically enable self-service account deletion with Amplify Auth.
If you have not yet created an Amplify Gen 2 app, visit the quickstart.
Allow users to delete their account
You can quickly set up account deletion for your users with the Amplify Libraries. Invoking the deleteUser
API to delete a user from the Auth category will also sign out your user.
If your application uses a Cognito User Pool, which is the default configuration, this action will only delete the user from the Cognito User Pool. It will have no effect if you are federating with a Cognito Identity Pool alone.
You can enable account deletion using the following method:
func deleteUser() async { do { try await Amplify.Auth.deleteUser() print("Successfully deleted user") } catch let error as AuthError { print("Delete user failed with error \(error)") } catch { print("Unexpected error: \(error)") }}
func deleteUser() -> AnyCancellable { Amplify.Publisher.create { try await Amplify.Auth.deleteUser() }.sink { if case let .failure(authError) = $0 { print("Delete user failed with error \(authError)") } } receiveValue: { print("Successfully deleted user") }}
We recommend you update your UI to let your users know that their account is deleted and test the functionality with a test user. Note that your user will be signed out of your application when they delete their account.