Docs

Delete users

There are two ways to delete users in Clerk: through the Clerk Dashboard or using the Clerk API.

Delete users in the Clerk Dashboard

To delete users in the Clerk Dashboard:

  1. Navigate to the Clerk Dashboard.
  2. In the navigation sidebar, select Users.
  3. 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.

Delete users using the Clerk API

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 { auth, clerkClient } from "@clerk/nextjs/server";
import { NextResponse } from 'next/server';

export async function DELETE() {
  const { userId } = auth();

  try {
    await clerkClient.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/clerk-sdk-node";

app.post('/deleteUser', (req, res) => {
  const userId = req.body.userId;

  try {
    await clerkClient.users.deleteUser(userId);
    return res.status(200).json({ message: 'User deleted' });
  }
  catch (error) {
    console.log(error);
    return res.status(500).json({ error: 'Error deleting user' });
  }
});
curl.sh
curl -XDELETE -H 'Authorization: CLERK_SECRET_KEY' 'https://api.clerk.com/v1/users/{user_id}'

Feedback

What did you think of this content?