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 @@ -193,7 +193,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
96 changes: 86 additions & 10 deletions src/pages/lib/auth/delete_user/q/platform/[platform].mdx
Original file line number Diff line number Diff line change
@@ -1,23 +1,99 @@
export const meta = {
title: `Delete user`,
description: `Delete a user`
title: `Delete user account`,
description: `Learn how to delete a user account.`
};

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. Users can delete their own account through your app interface by confirming intent before final removal. In this guide we will review how you can enable this for your users.
heatheramz marked this conversation as resolved.
Show resolved Hide resolved

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.

You should also be aware of which data this deletion includes and does not include. Depending on your application, data associated with your user may be stored in other resources such as Amazon DynamoDB or Amazon S3. It is recommended that you carefully evaluate this data and implement code to remove or otherwise sanitize it, if necessary, prior to giving users the ability to delete their own user record.
heatheramz marked this conversation as resolved.
Show resolved Hide resolved

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>

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

<Fragments fragments = {{ js: javascript2 }}/>
## Conclusion

import reactnative0 from '/src/fragments/lib/auth/js/delete_user.mdx';
Congratulations! You finished the **Delete user account** guide. In this guide, you learned how to enable account deletion for your users.

<Fragments fragments = {{ 'react-native': reactnative0 }}/>
## Next steps

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