Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JTBD Auth Delete User #6024

Merged
merged 14 commits into from
Oct 31, 2023
2 changes: 1 addition & 1 deletion src/directory/directory.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export const directory = {
filters: ['flutter']
},
{
title: 'Delete user',
title: 'Delete user account',
route: '/lib/auth/delete_user',
filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
Expand Down
94 changes: 84 additions & 10 deletions src/pages/lib/auth/delete_user/q/platform/[platform].mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const meta = {
title: `Delete user`,
description: `Delete a user`,
title: `Delete user account`,
description: `Learn how to delete a user account.`,
filterKey: 'platform',
supportedPlatforms: INTEGRATION_FILTER_OPTIONS
};
Expand All @@ -22,21 +22,95 @@ export const getStaticProps = (context) => {
};
};

import ios0 from '/src/fragments/lib/auth/native_common/delete_user/common.mdx';
<InlineFilter filters={["js", "react-native"]}>

<Fragments fragments={{ ios: ios0 }} />
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.

import flutter1 from '/src/fragments/lib/auth/native_common/delete_user/common.mdx';
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

<Fragments fragments={{ flutter: flutter1 }} />
## 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.

<Callout warning>

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](https://gist.github.com/aws-amplify-ops/27954c421bd72930874d48c15c284807) 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.

</Callout>

You can enable account deletion using the following method:

<BlockSwitcher>
<Block name="TypeScript">

```ts
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);
}
}
```
</Block>
<Block name="JavaScript">

```js
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);
}
}
```
</Block>
</BlockSwitcher>

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.

import javascript2 from '/src/fragments/lib/auth/js/delete_user.mdx';
## Conclusion

<Fragments fragments={{ js: javascript2 }} />
Congratulations! You finished the **Delete user account** guide. In this guide, you learned how to enable account deletion for your users.

import reactnative0 from '/src/fragments/lib/auth/js/delete_user.mdx';
## Next steps

<Fragments fragments={{ 'react-native': reactnative0 }} />
Now that you enabled account deletion you may also want to add some additional features. We recommend you learn more about:

<InlineFilter filters={["js"]}>

- [Manage user profile](/lib/auth/manageusers/q/platform/js/)
- [Set up password change and recovery](/lib/auth/password_management/q/platform/js/)

</InlineFilter>

<InlineFilter filters={["react-native"]}>

- [Manage user profile](/lib/auth/manageusers/q/platform/react-native/)
- [Set up password change and recovery](/lib/auth/password_management/q/platform/react-native/)

</InlineFilter>

</InlineFilter>

import ios0 from '/src/fragments/lib/auth/native_common/delete_user/common.mdx';

<Fragments fragments={{ ios: ios0 }} />

import flutter1 from '/src/fragments/lib/auth/native_common/delete_user/common.mdx';

<Fragments fragments={{ flutter: flutter1 }} />

import android3 from '/src/fragments/lib/auth/native_common/delete_user/common.mdx';

Expand Down