Users Delete users Delete users
There are two ways to delete users in Clerk: through the Clerk Dashboard or using the Clerk API .
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 .
To delete users using the Clerk API, you can use the deleteUser()
method from the users
sub-api of the clerkClient
instance.
app /api /delete-user /route.ts import { clerkClient } from '@clerk/nextjs/server'
import { NextResponse } from 'next/server'
export async function DELETE () {
const userId = 'user_123'
try {
const client = await clerkClient ()
await client . users .deleteUser (userId)
return NextResponse .json ({ message : 'User deleted' })
} catch (error) {
console .log (error)
return NextResponse .json ({ error : 'Error deleting user' })
}
}
delete-user.ts 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' })
}
})
terminal
curl 'https://api.clerk.com/v1/users/{user_id}' -X DELETE -H 'Authorization:Bearer YOUR_SECRET_KEY ' -H 'Content-Type:application/json'
Last updated on Jan 21, 2025