# Allow currently logged in user of Web App to delete their account

**URL:** <https://community.auth0.com/t/allow-currently-logged-in-user-of-web-app-to-delete-their-account/60022>\
**Category:** Get Help\
**Tags:** api\
**Created:** [March 25, 2021, 12:13am UTC](https://community.auth0.com/t/allow-currently-logged-in-user-of-web-app-to-delete-their-account/60022 "2021-03-25T00:13:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jinteki](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jinteki/32/28358_2.png) [@jinteki](https://community.auth0.com/u/jinteki)\
**Post date:** [March 25, 2021, 12:13am UTC](https://community.auth0.com/t/allow-currently-logged-in-user-of-web-app-to-delete-their-account/60022/1 "2021-03-25T00:13:28Z")

</div>

Hi,  
I am rookie web developer, that is developing a SPA using NextJS and React. Authentication is handled by Auth0 via ‘auth0/nextjs-auth0’. This is the only Auth0 package that I have installed.

**From within my web app, if the currently logged in user decides to click on ‘Delete Account’ how do I make the call to Auth0 to delete that user?**

In the Auth0 Dashboard \> APIs, I can see two APIs defined.

1. Auth0 Management API (system API): [https://myapp.auth0.com/api/v2/](https://myapp.auth0.com/api/v2/) already exists.
2. MyApp (custom API)

I presume I can therefore make a call to ‘[https://myapp.auth0.com/api/v2/users/{id}](https://myapp.auth0.com/api/v2/users/%7Bid%7D)’?

If so how or where do I pass/set the scope?  
Which scope is required ‘delete:users’ or ‘delete:current\_user’?

Thanks.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [March 25, 2021, 6:40pm UTC](https://community.auth0.com/t/allow-currently-logged-in-user-of-web-app-to-delete-their-account/60022/3 "2021-03-25T18:40:28Z")

</div>

Hi @jinteki,

Welcome to the Community!

It is possible to get an Access Token for the Management API so that the current user can update their profile, however, they will not be able to delete their account. The DELETE [/api/v2/users/{id}](https://auth0.com/docs/api/management/v2#!/Users/delete_users_by_id) endpoint requires the `delete:users` permission which is not in the list of [available scopes and endpoints for SPAs](https://auth0.com/docs/tokens/management-api-access-tokens/get-management-api-tokens-for-single-page-applications#available-scopes-and-endpoints).

You can read more about getting an Access Token for your SPA here: [Get Management API Access Tokens for Single-Page Applications](https://auth0.com/docs/tokens/management-api-access-tokens/get-management-api-tokens-for-single-page-applications)

Here are a couple of options you might consider:

1. Allow users to deactivate their account by storing a flag in the user’s `app_metadata` that indicates whether the account is active or not. You could use the [PATCH /api/v2/users/{id}](https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id) endpoint for this and request the `update:current_user_metadata` as a scope for the `Auth0Provider` in the app.
2. Create a [Machine-to-Machine application](https://auth0.com/docs/applications/set-up-an-application/register-machine-to-machine-applications) for your own custom API and authorize it to use the `delete:users` scope. Instead of the client making the request to the Management API, it would be the backend. For example, if you are using the [Node Management API client](https://github.com/auth0/node-auth0):

```auto
  management.users.delete({ id: USER_ID }, function (err) {
    if (err) {
      // Handle error.
    }
 
    // User deleted.
  });

```

---

<div class="post-metadata">

**Author:** ![jinteki](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jinteki/32/28358_2.png) [@jinteki](https://community.auth0.com/u/jinteki)\
**Post date:** [March 26, 2021, 7:30pm UTC](https://community.auth0.com/t/allow-currently-logged-in-user-of-web-app-to-delete-their-account/60022/4 "2021-03-26T19:30:19Z")

</div>

Hi @stephanie.chamblee,

Thanks for the reply. I implemented the second option of MtM and it all works.

Here are the steps that I went through in case it is useful for someone else.

1. Installed node-auth0.
2. From Dashboard \> Applications, created a new MtM application, ‘MyApp MtM’.
3. Clicked on MyApp MtM \> APIs, and set the Auth0 Management API authorized switch to ‘on’.
4. Clicked on the small ‘down arrowhead’ to the right of the Authorized switch and selected delete:users from the Permissions.

Then from my Web App I was able to call my deleteUser API which implements:

```
const ManagementClient = require('auth0').ManagementClient

const management = new ManagementClient({
                domain: 'my-app.auth0.com',
                clientId: '<MyApp MtM clientId>',
                clientSecret: '<MyApp MtM clientSecret>',
                scope: 'delete:users'
            })

        management.deleteUser({ id: auth0UserId }, function (err) {
            if (err) {
              // Handle error.
              console.log('> Delete Auth0 user, err = ', err)
            }
          
            // User deleted.
            console.log('Auth0 user deleted')
        })

```

Note: the ManagementClient now uses **management.deleteUser**

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [March 26, 2021, 7:32pm UTC](https://community.auth0.com/t/allow-currently-logged-in-user-of-web-app-to-delete-their-account/60022/5 "2021-03-26T19:32:22Z")

</div>

That’s great, thanks for sharing your solution in detail!

---

<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:** [April 10, 2021, 7:32pm UTC](https://community.auth0.com/t/allow-currently-logged-in-user-of-web-app-to-delete-their-account/60022/6 "2021-04-10T19:32:29Z")

</div>

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