Skip to main content
Docs

You are viewing an archived version of the docs.Go to latest version

Deleting users

Clerk currently supports deleting users through our backend API.

The deleteUser() method takes a single argument: the user ID of the user you want to delete. It can be accessed from the users sub-api of the clerkClient instance.

app/private/route.ts
import { clerkClient } from "@clerk/nextjs";
import { NextResponse } from 'next/server';

export async function DELETE(request: Request) {
  const { userId } = await request.body.json();

  try {
    await clerkClient.users.deleteUser(userId);
    return NextResponse.json({ message: 'Success' });
  }
  catch (error) {
    console.log(error);
    return NextResponse.json({ error: 'Error deleting user' });
  }
}
pages/api/private.ts
import { clerkClient } from "@clerk/nextjs/server";
import { NextApiRequest, NextApiResponse } from "next";

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
  const userId = req.body.userId;

  try {
    await clerkClient.users.deleteUser(userId);
    return res.status(200).json({ message: 'Success' });
  }
  catch (error) {
    console.log(error);
    return res.status(500).json({ error: 'Error deleting user' });
  }
}
private.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: 'Success' });
  }
  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?

Last updated on