Skip to main content
Docs

deleteUser()

Deletes a User given a valid ID.

function deleteUser(userId: string): Promise<User>
  • Name
    userId
    Type
    string
    Description

    The ID of the user to delete.

Note

Using clerkClient varies based on your framework. Refer to the JS Backend SDK overview for usage details, including guidance on how to access the userId and other properties.

const userId = 'user_123'

const response = await clerkClient.users.deleteUser(userId)
app/api/example/route.ts
import { auth, clerkClient } from '@clerk/nextjs/server'
import { NextResponse } from 'next/server'

export async function GET() {
  const { userId } = await auth()

  await clerkClient.users.deleteUser(userId)

  return NextResponse.json({ success: true })
}
src/api/example.ts
import type { APIRoute } from 'astro'
import { clerkClient } from '@clerk/astro/server'

export const GET: APIRoute = async (context) => {
  const { userId } = context.locals.auth()

  await clerkClient(context).users.deleteUser(userId)

  return new Response(JSON.stringify({ success: true }), { status: 200 })
}
public.ts
import { getAuth, clerkClient } from '@clerk/express'

app.post('/deleteUser', async (req, res) => {
  const { userId } = getAuth(req)

  await clerkClient.users.deleteUser(userId)

  res.status(200).json({ success: true })
})
app/routes/example.tsx
import { clerkClient, getAuth } from '@clerk/react-router/server'
import type { Route } from './+types/example'

export async function loader(args: Route.LoaderArgs) {
  const { userId } = await getAuth(args)

  await clerkClient.users.deleteUser(userId)

  return { success: true }
}
app/routes/api/example.tsx
import { json } from '@tanstack/react-start'
import { createFileRoute } from '@tanstack/react-router'
import { auth, clerkClient } from '@clerk/tanstack-react-start/server'

export const ServerRoute = createFileRoute('/api/example')({
  server: {
    handlers: {
      GET: async () => {
        const { userId } = await auth()

        await clerkClient().users.deleteUser(userId)

        return json({ success: true })
      },
    },
  },
})

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint DELETE/users/{user_id}. See the BAPI reference for more information.

Here's an example of making a request directly to the endpoint using cURL.

terminal
  curl 'https://api.clerk.com/v1/users/{user_id}' -X DELETE -H 'Authorization:Bearer YOUR_SECRET_KEY' -H 'Content-Type:application/json'

Feedback

What did you think of this content?

Last updated on