Page updated Jan 16, 2024

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. In this guide, we will review how you can enable this feature for your users.

Before you begin, you will need:

  • An Amplify project with the Auth category configured
  • The Amplify Libraries installed and configured
  • A test user to delete

Allow my 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.

Before invoking the deleteUser API, you may need to first delete associated user data that is not stored in Cognito. For example, if you are using Amplify GraphQL API to persist user data, you could follow these instructions to delete associated user data. This allows you to address any guidelines (such as GDPR) that require your app to delete data associated with a user who deletes their account.

You can enable account deletion using the following method:

import { Auth } from 'aws-amplify'; async function deleteUser() { try { const result = await Auth.deleteUser(); console.log(result); } catch (error) { console.log('Error deleting user', error); } }
1import { Auth } from 'aws-amplify';
2
3async function deleteUser() {
4 try {
5 const result = await Auth.deleteUser();
6 console.log(result);
7 } catch (error) {
8 console.log('Error deleting user', error);
9 }
10}
import { Auth } from 'aws-amplify'; async function deleteUser() { try { const result = await Auth.deleteUser(); console.log(result); } catch (error) { console.log('Error deleting user', error); } }
1import { Auth } from 'aws-amplify';
2
3async function deleteUser() {
4 try {
5 const result = await Auth.deleteUser();
6 console.log(result);
7 } catch (error) {
8 console.log('Error deleting user', error);
9 }
10}

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.

Conclusion

Congratulations! You finished the Delete user account guide. In this guide, you learned how to enable account deletion for your users.

Next steps

Now that you enabled account deletion you may also want to add some additional features. We recommend you learn more about: