# Clerk user deleted notifications on your phone

> Get a push notification when a user deletes their account or is removed from your Clerk application.

- Company: Clerk (https://www.justpush.io/recipes/clerk)
- Event: `user.deleted` (user.deleted)
- Tags: Backend & auth, Sign-ups & users
- Install: https://studio.justpush.io/recipes/clerk/user-deleted
- Web page: https://www.justpush.io/recipes/clerk/user-deleted

## Setup

1. Click Install in Studio and sign in. The recipe is added to your account and you get a personal webhook URL.
2. In the Clerk Dashboard, open Webhooks and click Add Endpoint.
3. Paste your webhook URL (shown in Studio after install) as the Endpoint URL and subscribe to user.deleted.
4. Click Create. The endpoint's Testing tab can send an example event.
5. In the Clerk Dashboard, open **Webhooks → Add Endpoint** and subscribe to **user.deleted**. Webhooks are set up per instance, so add the endpoint to your production instance.
6. Clerk's `user.deleted` payload only contains the user's ID (and `external_id` when you set one), not their name or email. To look them up, search the ID in your own database.
7. Use the endpoint's **Testing** tab and **Send Example** to try it.
8. Clerk sends webhooks through Svix and signs every delivery (`svix-id`, `svix-timestamp`, `svix-signature`), but JustPush doesn't check that signature yet, so keep your endpoint URL private.

## Code

Studio calls `handleRequest(request)` with the incoming webhook (`{ method, headers, body, query, raw }`) and sends the message object it returns. Returning `null` sends nothing.

```js
// Clerk → user.deleted
// Fires when a user deletes their account, or is removed in the Clerk Dashboard or API.
// Clerk only sends the user's ID (and external ID, if set), not their name or email.
// Docs: https://clerk.com/docs/guides/development/webhooks/syncing

// A trimmed string (or number), or null.
function text(value) {
    if (typeof value === "number" && Number.isFinite(value)) return String(value)
    return typeof value === "string" && value.trim() ? value.trim() : null
}

function handleRequest(request) {
    const body = request.body && typeof request.body === "object" ? request.body : {}
    const data = body.data && typeof body.data === "object" ? body.data : null

    // Guard: only user.deleted, so other Clerk events on this integration stay quiet.
    if (body.type !== "user.deleted" || !data) {
        console.log(`Ignoring Clerk "${body.type ?? "unknown"}" event`)
        return null
    }

    const id = text(data.id)
    const external = text(data.external_id)

    return {
        title: "🗑️ User deleted",
        message: `${id ?? "A user"} was deleted${external ? ` (external ID ${external})` : ""}`,
        topic: "Clerk",
        priority: 0, // Normal: losing a user is worth knowing
    }
}
```

## Clerk user.deleted webhook payload (sample)

```json
{
  "data": {
    "id": "user_29wBMCtzATuFJut8jO2VNTVekS4",
    "object": "user",
    "deleted": true
  },
  "type": "user.deleted",
  "object": "event",
  "timestamp": 1790670591835,
  "instance_id": "ins_123",
  "event_attributes": {
    "http_request": {
      "client_ip": "192.0.2.10",
      "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36"
    }
  }
}
```

## FAQ

### Does this work on iPhone and Android?

Yes. Install the JustPush app from the App Store or Google Play and sign in. Every phone signed in to your account gets the notification.

### Do I need to write code?

No. Install the recipe in Studio, paste your webhook URL into Clerk and you are done. The code is there if you want to change the text, the sound or the buttons.

### Can I change what the notification says?

Yes. After install the recipe's code is yours. Edit it in Studio and test it against the sample payload before you save.

### What does it cost?

JustPush is free for 30 days. After that it's $19.99 a year, or $39.99 once. There is no extra charge for recipes.
