# Secure flow to let user delete their own account

**URL:** <https://community.auth0.com/t/secure-flow-to-let-user-delete-their-own-account/150908>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [November 3, 2024, 4:07pm UTC](https://community.auth0.com/t/secure-flow-to-let-user-delete-their-own-account/150908 "2024-11-03T16:07:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![eva](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eva/32/61942_2.png) [@eva](https://community.auth0.com/u/eva)\
**Post date:** [November 3, 2024, 4:07pm UTC](https://community.auth0.com/t/secure-flow-to-let-user-delete-their-own-account/150908/1 "2024-11-03T16:07:04Z")

</div>

Coming from Firebase, my understanding of the secure way to let the user delete their own account is by forcing them to reauthenticate right before doing so. However, it looks like authentication through Auth0 goes through the universal auth, but deleting a user goes through my own server. I’m struggling to figure out how to connect those two. Is reauthenticating the user even necessary through Auth0? What is the proper flow to let the user delete their own account?

---

<div class="post-metadata">

**Author:** ![marybeth.hunter](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marybeth.hunter/32/61955_2.png) [@marybeth.hunter](https://community.auth0.com/u/marybeth.hunter)\
**Post date:** [November 6, 2024, 6:04pm UTC](https://community.auth0.com/t/secure-flow-to-let-user-delete-their-own-account/150908/3 "2024-11-06T18:04:41Z")

</div>

Hi @eva!

Welcome to the Auth0 Community!

We recommend using the client credentials flow via a backend process; see a related Community post’s solution here: [Is it able to get management API access token and call management APIs via a React Native mobile application?](https://community.auth0.com/t/is-it-able-to-get-management-api-access-token-and-call-management-apis-via-a-react-native-mobile-application/79255)

More specifically, you can do this with the Management API with an M2M token following this [doc](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-access-tokens-for-production). You could create a self-hosted API with an endpoint that is configured to get an M2M token with the appropriate scopes for the Management API in the backend. Given that the API is hosted on the server, the client secret can be stored there securely. If an end-user from your app requests account deletion, then you call out to your API endpoint passing the logged-in `user_id` across. You could configure the endpoint to delete the account via the Management API’s [Delete a User endpoint](https://auth0.com/docs/api/management/v2/users/delete-users-by-id), and then you redirect the user to the logout endpoint.

Please let me know if you have any additional questions!

Best,

Mary Beth

---

<div class="post-metadata">

**Author:** ![eva](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eva/32/61942_2.png) [@eva](https://community.auth0.com/u/eva)\
**Post date:** [November 7, 2024, 11:46am UTC](https://community.auth0.com/t/secure-flow-to-let-user-delete-their-own-account/150908/5 "2024-11-07T11:46:00Z")

</div>

Thanks for your response. How do I verify on my server that the user id in the request matches the logged in user?

---

<div class="post-metadata">

**Author:** ![marybeth.hunter](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marybeth.hunter/32/61955_2.png) [@marybeth.hunter](https://community.auth0.com/u/marybeth.hunter)\
**Post date:** [November 7, 2024, 3:40pm UTC](https://community.auth0.com/t/secure-flow-to-let-user-delete-their-own-account/150908/6 "2024-11-07T15:40:56Z")

</div>

Hi @eva!

To verify that the `user_id` from the request matches the logged-in user, you can extract the user ID from the JWT (JSON Web Token) included in the request’s Authorization header. Then, you use the Auth0 Management API to validate that the ID is associated with the currently authenticated user on your server; essentially, you decode the JWT and compare the user ID within it to the expected user ID based on the current session.

**Key steps:**

- **Retrieve the JWT from the request:**

- **Decode the JWT:**

- **Validate the user ID:**

Please let me know if you have any additional questions!

Thanks,

Mary Beth

---

<div class="post-metadata">

**Author:** ![eva](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eva/32/61942_2.png) [@eva](https://community.auth0.com/u/eva)\
**Post date:** [November 7, 2024, 8:58pm UTC](https://community.auth0.com/t/secure-flow-to-let-user-delete-their-own-account/150908/7 "2024-11-07T20:58:46Z")

</div>

So there’s no need to reauthenticate the user? There isn’t a risk of privilege escalation?

---

<div class="post-metadata">

**Author:** ![marybeth.hunter](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marybeth.hunter/32/61955_2.png) [@marybeth.hunter](https://community.auth0.com/u/marybeth.hunter)\
**Post date:** [November 12, 2024, 4:39pm UTC](https://community.auth0.com/t/secure-flow-to-let-user-delete-their-own-account/150908/8 "2024-11-12T16:39:46Z")

</div>

Hi @eva,

Thank you for your patience! You can reauthenticate the user or add [Step-Up Authentication](https://auth0.com/docs/secure/multi-factor-authentication/step-up-authentication) to the delete functionality in your app/API.

Thanks,

Mary Beth

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [November 26, 2024, 4:40pm UTC](https://community.auth0.com/t/secure-flow-to-let-user-delete-their-own-account/150908/9 "2024-11-26T16:40:24Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
