# Delete user though Auth0.swift

**URL:** <https://community.auth0.com/t/delete-user-though-auth0-swift/114539>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [August 25, 2023, 6:32pm UTC](https://community.auth0.com/t/delete-user-though-auth0-swift/114539 "2023-08-25T18:32:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakkipally](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jakkipally/32/50200_2.png) [@jakkipally](https://community.auth0.com/u/jakkipally)\
**Post date:** [August 25, 2023, 6:32pm UTC](https://community.auth0.com/t/delete-user-though-auth0-swift/114539/1 "2023-08-25T18:32:54Z")

</div>

Hey,

I’ve got an Auth0 app though Auth0.swift for my iOS app, and I got it to work properly but I need to have a delete user button. One problem with this is that based on what I’ve read theres no way to delete users though the sdk and I found a related question here [I need to delete user account in my iOS project(swift) is that applicable from mobile side?](https://community.auth0.com/t/i-need-to-delete-user-account-in-my-ios-project-swift-is-that-applicable-from-mobile-side/111198) but I need help in creating an API. Can someone pls help me understand how to create an backend api using node?

Here’s my current code I got from a quickstart:

```auto
const express = require('express');
const app = express();
const { auth, requiredScopes } = require('express-oauth2-jwt-bearer');

// Authorization middleware. When used, the Access Token must
// exist and be verified against the Auth0 JSON Web Key Set.
const checkJwt = auth({
  audience: 'http://GitaApi:5000',
  issuerBaseURL: `https://dev-1lh8f0uy7cxikoik.us.auth0.com/`,
});

// This route doesn't need authentication
app.get('/api/public', function(req, res) {
  res.json({
    message: 'Hello from a public endpoint! You don\'t need to be authenticated to see this.'
  });
});

// This route needs authentication
app.get('/api/private', checkJwt, function(req, res) {
  res.json({
    message: 'Hello from a private endpoint! You need to be authenticated to see this.'
  });
});

const checkScopes = requiredScopes('read:messages');

app.get('/api/private-scoped', checkJwt, checkScopes, function(req, res) {
  res.json({
    message: 'Hello from a private endpoint! You need to be authenticated and have a scope of read:messages to see this.'
  });
});

app.listen(3000, function() {
  console.log('Listening on http://localhost:3000');
});

```

Thanks,  
Arjun

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 29, 2023, 10:24pm UTC](https://community.auth0.com/t/delete-user-though-auth0-swift/114539/3 "2023-08-29T22:24:45Z")

</div>

Hey there @jakkipally welcome to the community !

> [@jakkipally](#):
>
> One problem with this is that based on what I’ve read theres no way to delete users though the sdk

This is correct - As this action requires the Management API and thus client credentials, it cannot be safely carried out client side ([see public vs. confidential clients](https://auth0.com/docs/get-started/applications/confidential-and-public-applications#:~:text=According%20to%20the%20OAuth%202.0,authentication%20the%20applications%20can%20use.)).

Your node API will need to utilize the [node-auth0](https://github.com/auth0/node-auth0) library and in particular implement the [delete users function](https://auth0.github.io/node-auth0/UsersManager.html#delete).

Your API might look something like this:

```auto
const express = require('express');
const bodyParser = require('body-parser');
const Auth0ManagementClient = require('auth0').ManagementClient;

const app = express();
const port = 3000;

// Auth0 Management API Client
const auth0 = new Auth0ManagementClient({
  domain: 'YOUR_AUTH0_DOMAIN',
  clientId: 'YOUR_CLIENT_ID',
  clientSecret: 'YOUR_CLIENT_SECRET',
  scope: 'read:users update:users delete:users'
});

app.use(bodyParser.json());

// Endpoint to delete a user by their Auth0 User ID
app.delete('/delete-user/:userId', (req, res) => {
  const userId = req.params.userId;

  auth0.deleteUser({ id: userId }, (err) => {
    if (err) {
      console.error('Error deleting user:', err);
      return res.status(500).json({ error: 'Failed to delete user' });
    }

    res.status(200).json({ message: 'User deleted successfully' });
  });
});

app.listen(port, () => {
  console.log(`Server running on http://localhost:${port}`);
});

```

I have not tested this code and am sharing just as an example 🙂

Hope this helps point you in the correct direction!

---

<div class="post-metadata">

**Author:** ![jakkipally](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jakkipally/32/50200_2.png) [@jakkipally](https://community.auth0.com/u/jakkipally)\
**Post date:** [August 31, 2023, 3:01pm UTC](https://community.auth0.com/t/delete-user-though-auth0-swift/114539/4 "2023-08-31T15:01:12Z")

</div>

Yes, after some tweaking, I got it to work. Thank you!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 31, 2023, 5:22pm UTC](https://community.auth0.com/t/delete-user-though-auth0-swift/114539/5 "2023-08-31T17:22:40Z")

</div>

That’s great news, thanks for confirming here! 🙂

---

<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:** [September 14, 2023, 5:23pm UTC](https://community.auth0.com/t/delete-user-though-auth0-swift/114539/6 "2023-09-14T17:23:21Z")

</div>

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