Delete users
There are two ways to delete users in Clerk: in the Clerk Dashboard or using the Backend API.
In the Clerk Dashboard
To delete users in the Clerk Dashboard:
- At the top of the Clerk Dashboard, select Users.
- You can either select the user and then in the side navigation menu, select Delete user, or select the menu icon on the right side of the user's row and select Delete user.
Using the Backend API
You can delete users in your app using Clerk's Backend API.
Use the following tabs to see examples of how to delete users using one of the following:
- Frontend SDKs, such as Next.js, React, or Remix
- Express
- cURL
The following example shows how to delete a user using the JavaScript Backend SDK's deleteUser()
method from the users
sub-api of the clerkClient
instance.
export async function DELETE() {
const userId = 'user_123'
try {
await clerkClient.users.deleteUser(userId)
return Response.json({ message: 'User deleted' })
} catch (error) {
console.log(error)
return Response.json({ error: 'Error deleting user' })
}
}
If you're using Next.js, you must await
the instantiation of the clerkClient
instance, like so:
const client = await clerkClient()
const response = await client.users.deleteUser(userId)
import { clerkClient } from '@clerk/express'
app.post('/deleteUser', async (req, res) => {
const userId = req.body.userId
try {
await clerkClient.users.deleteUser(userId)
res.status(200).json({ message: 'User deleted' })
} catch (error) {
console.log(error)
res.status(500).json({ error: 'Error deleting user' })
}
})
curl 'https://api.clerk.com/v1/users/{user_id}' -X DELETE -H 'Authorization:Bearer YOUR_SECRET_KEY' -H 'Content-Type:application/json'
Feedback
Last updated on