Skip to Content
Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.com

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' }); } }

Last updated on November 21, 2023

What did you think of this content?

Clerk © 2023