[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EZMRFDW6HKRX9PDPKBZG8C":3,"skill-same:01M7EZMRFDW6HKRX9PDPKBZG8C":60},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":29,"commitSha":30,"skillDirectory":31,"forksCount":14,"repositoryHtmlUrl":32,"repositoryHomepageUrl":6,"ownerHtmlUrl":33,"ownerBlogUrl":6,"ownerDescription":34,"updatedAt":35,"install":36,"resources":49},"01M7EZMRFDW6HKRX9PDPKBZG8C","clerk-webhooks",null,"Clerk webhooks for real-time events and data syncing. Verify with verifyWebhook from the framework-specific package. Handle user, session, organization, billing, and payment events. Build event-driven features like database sync, notifications, and integrations.","Sebastian-Tunjuelo\u002FHaki-Soft","Sebastian-Tunjuelo","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F184461480?v=4","01M7EZMAAPZSAZJPJYAGKNMNE1","Sebastian","01M7EZMABM14RDFCH05C43FMSC",0,"MIT","https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo\u002FHaki-Soft\u002Fblob\u002Fmaster\u002F.agents\u002Fskills\u002Fclerk-webhooks\u002FSKILL.md",[],[],"2026-11-16 10:05:34",false,"---\nname: clerk-webhooks\ndescription: Clerk webhooks for real-time events and data syncing. Verify with verifyWebhook\n  from the framework-specific package. Handle user, session, organization, billing, and\n  payment events. Build event-driven features like database sync, notifications, and\n  integrations.\nallowed-tools: WebFetch\nlicense: MIT\nmetadata:\n  author: clerk\n  version: 1.2.0\ncompatibility: Requires CLERK_WEBHOOK_SIGNING_SECRET (svix signing secret from Clerk dashboard)\n---\n\n# Webhooks\n\nOutput complete, working webhook handlers with `verifyWebhook(req)` verification in every handler.\n\n## When to Use Webhooks\n\nWebhooks are **asynchronous and eventually consistent**. Delivery is fast but not guaranteed to be immediate, and may occasionally fail (Svix retries on a fixed schedule). Use them for:\n\n- Database sync (a separate users \u002F orgs table that follows Clerk)\n- Notifications (welcome emails, Slack pings, internal alerts)\n- Integrations triggered by lifecycle events\n\nDo NOT rely on webhook delivery as part of a synchronous flow such as onboarding (\"user signs up, then we read X from our DB\"). For data the user just created, read it from the [Clerk session token](https:\u002F\u002Fclerk.com\u002Fdocs\u002Fguides\u002Fsessions\u002Fsession-tokens) or call the Backend API directly. Webhooks fill the gap when you need data about *other* users or events the session token doesn't carry.\n\n## Verify Every Webhook\n\nUse `verifyWebhook(req)` from the framework-specific package (`@clerk\u002Fnextjs\u002Fwebhooks`, `@clerk\u002Fexpress\u002Fwebhooks`, etc.). It reads `CLERK_WEBHOOK_SIGNING_SECRET` automatically and throws on bad signatures. Skipping verification, even for notification-only handlers, exposes the endpoint to spoofed events.\n\n## Keep the Webhook Route Unprotected\n\nWebhook deliveries carry no user session. `verifyWebhook()` is the only check the route needs. A bare `clerkMiddleware()` protects nothing, so the route is already reachable. Don't call `auth.protect()` for `\u002Fapi\u002Fwebhooks(.*)`, in middleware or in the handler. A project that does returns `404` for every delivery until that call is removed. See [Ensure the webhook route is public](https:\u002F\u002Fclerk.com\u002Fdocs\u002Fguides\u002Fdevelopment\u002Fwebhooks\u002Fsyncing#ensure-the-webhook-route-is-public).\n\n## Complete Webhook Handler (Next.js App Router)\n\n```typescript\n\u002F\u002F app\u002Fapi\u002Fwebhooks\u002Froute.ts\nimport { verifyWebhook } from '@clerk\u002Fnextjs\u002Fwebhooks'\nimport { NextRequest } from 'next\u002Fserver'\nimport { db } from '@\u002Flib\u002Fdb'\n\nexport async function POST(req: NextRequest) {\n  \u002F\u002F ALWAYS verify - never skip, even for notification-only handlers\n  let evt\n  try {\n    evt = await verifyWebhook(req) \u002F\u002F uses CLERK_WEBHOOK_SIGNING_SECRET automatically\n  } catch (err) {\n    console.error('Webhook verification failed:', err)\n    return new Response('Verification failed', { status: 400 })\n  }\n\n  if (evt.type === 'user.created') {\n    const { id, email_addresses, first_name, last_name } = evt.data\n    const email = email_addresses[0]?.email_address\n    const name = `${first_name ?? ''} ${last_name ?? ''}`.trim()\n    await db.users.create({ data: { clerkId: id, email, name } })\n  }\n\n  if (evt.type === 'user.updated') {\n    const { id, email_addresses, first_name, last_name } = evt.data\n    const email = email_addresses[0]?.email_address\n    await db.users.update({ where: { clerkId: id }, data: { email, first_name, last_name } })\n  }\n\n  if (evt.type === 'user.deleted') {\n    const { id } = evt.data\n    await db.users.delete({ where: { clerkId: id } })\n  }\n\n  if (evt.type === 'organizationMembership.created') {\n    const { organization, public_user_data, role } = evt.data\n    const orgId = organization.id\n    const userId = public_user_data.user_id\n    await db.teamMembers.create({ data: { orgId, userId, role } })\n  }\n\n  if (evt.type === 'organizationMembership.deleted') {\n    const { organization, public_user_data } = evt.data\n    const orgId = organization.id\n    const userId = public_user_data.user_id\n    await db.teamMembers.delete({ where: { orgId_userId: { orgId, userId } } })\n  }\n\n  return new Response('OK', { status: 200 })\n}\n```\n\n## Full Example: Welcome Email (Resend) + Slack Notification on user.created\n\nNotification-only handlers still verify the signature. Same pattern as the database-sync handler:\n\n```typescript\n\u002F\u002F app\u002Fapi\u002Fwebhooks\u002Froute.ts\nimport { verifyWebhook } from '@clerk\u002Fnextjs\u002Fwebhooks'\nimport { NextRequest } from 'next\u002Fserver'\nimport { Resend } from 'resend'\n\nconst resend = new Resend(process.env.RESEND_API_KEY)\n\nexport async function POST(req: NextRequest) {\n  \u002F\u002F Step 1: ALWAYS verify the webhook signature - NEVER skip this\n  let evt\n  try {\n    evt = await verifyWebhook(req) \u002F\u002F uses CLERK_WEBHOOK_SIGNING_SECRET env var\n  } catch (err) {\n    console.error('Webhook verification failed:', err)\n    return new Response('Verification failed', { status: 400 })\n  }\n\n  \u002F\u002F Step 2: Listen for user.created event\n  if (evt.type === 'user.created') {\n    \u002F\u002F Step 3: Extract user email and name from webhook payload\n    const { id, email_addresses, first_name, last_name } = evt.data\n    const email = email_addresses[0]?.email_address\n    const name = `${first_name ?? ''} ${last_name ?? ''}`.trim()\n\n    \u002F\u002F Step 4: Call Resend API to send welcome email\n    await resend.emails.send({\n      from: 'noreply@yourdomain.com',\n      to: email,\n      subject: 'Welcome!',\n      html: `\u003Cp>Hi ${name}, welcome to our app!\u003C\u002Fp>`,\n    })\n\n    \u002F\u002F Step 5: Post notification to Slack channel\n    await fetch(process.env.SLACK_WEBHOOK_URL!, {\n      method: 'POST',\n      headers: { 'Content-Type': 'application\u002Fjson' },\n      body: JSON.stringify({\n        text: `New user signed up: ${name} (${email})`,\n      }),\n    })\n  }\n\n  \u002F\u002F Always return 200 to acknowledge receipt\n  return new Response('OK', { status: 200 })\n}\n```\n\n## Full Example: Organization Membership Sync to Database\n\n```typescript\n\u002F\u002F app\u002Fapi\u002Fwebhooks\u002Froute.ts\nimport { verifyWebhook } from '@clerk\u002Fnextjs\u002Fwebhooks'\nimport { NextRequest } from 'next\u002Fserver'\nimport { db } from '@\u002Flib\u002Fdb' \u002F\u002F your database client\n\nexport async function POST(req: NextRequest) {\n  \u002F\u002F ALWAYS verify signature - never skip, even for simple handlers\n  let evt\n  try {\n    evt = await verifyWebhook(req) \u002F\u002F uses CLERK_WEBHOOK_SIGNING_SECRET env var\n  } catch (err) {\n    console.error('Webhook verification failed:', err)\n    return new Response('Verification failed', { status: 400 })\n  }\n\n  if (evt.type === 'organization.created') {\n    const { id, name } = evt.data\n    await db.workspaces.create({\n      data: { orgId: id, name, createdAt: new Date() },\n    })\n  }\n\n  if (evt.type === 'organizationMembership.created') {\n    \u002F\u002F Extract organization ID, user ID, and role from payload\n    const { organization, public_user_data, role } = evt.data\n    const orgId = organization.id\n    const userId = public_user_data.user_id\n\n    \u002F\u002F Add to team_members table\n    await db.team_members.create({\n      data: { orgId, userId, role },\n    })\n\n    \u002F\u002F Create workspace record for new member\n    await db.workspaces.create({\n      data: { orgId, userId, createdAt: new Date() },\n    })\n  }\n\n  if (evt.type === 'organizationMembership.deleted') {\n    \u002F\u002F Extract organization ID and user ID from payload\n    const { organization, public_user_data } = evt.data\n    const orgId = organization.id\n    const userId = public_user_data.user_id\n\n    \u002F\u002F Remove from team_members table\n    await db.team_members.delete({\n      where: { orgId, userId },\n    })\n\n    \u002F\u002F Remove workspace record\n    await db.workspaces.deleteMany({\n      where: { orgId, userId },\n    })\n  }\n\n  \u002F\u002F Return 200 status on success\n  return new Response('OK', { status: 200 })\n}\n```\n\n## Other Frameworks\n\nFor Express, Astro, Fastify, Nuxt, React Router, and TanStack Start, use the framework-specific `verifyWebhook` adapter. Each Clerk SDK package ships its own (`@clerk\u002Fexpress\u002Fwebhooks`, `@clerk\u002Fastro\u002Fwebhooks`, `@clerk\u002Ffastify\u002Fwebhooks`, etc.).\n\nSee `references\u002Fframeworks.md` for full handler examples per framework.\n\n## Type Narrowing for `evt.data`\n\n`verifyWebhook` returns `WebhookEvent`, a discriminated union of all event types. Narrow with `evt.type` to get type-safe access to `evt.data`:\n\n```typescript\nconst evt = await verifyWebhook(req)\n\nif (evt.type === 'user.created') {\n  \u002F\u002F evt.data is now UserJSON, autocompletes id, email_addresses, etc.\n  console.log(evt.data.id)\n}\n```\n\nFor manual typing of nested payloads, import the JSON types from your framework's webhook subpath: `DeletedObjectJSON`, `EmailJSON`, `OrganizationInvitationJSON`, `OrganizationJSON`, `OrganizationMembershipJSON`, `SessionJSON`, `SMSMessageJSON`, `UserJSON`.\n\n## Payload Field Reference\n\n### User events (`user.created`, `user.updated`, `user.deleted`)\n```typescript\nconst {\n  id,                  \u002F\u002F Clerk user ID\n  email_addresses,     \u002F\u002F array; [0].email_address is primary email\n  first_name,\n  last_name,\n  image_url,\n  public_metadata,\n} = evt.data\n```\n\n### Organization events (`organization.created`, `organization.updated`, `organization.deleted`)\n```typescript\nconst {\n  id,    \u002F\u002F org ID\n  name,  \u002F\u002F org name\n  slug,\n} = evt.data\n```\n\n### Organization Membership events (`organizationMembership.created`, `organizationMembership.updated`, `organizationMembership.deleted`)\n```typescript\nconst {\n  organization,        \u002F\u002F { id, name, ... }\n  public_user_data,    \u002F\u002F { user_id, first_name, last_name, ... }\n  role,                \u002F\u002F e.g. 'org:admin', 'org:member'\n} = evt.data\n\u002F\u002F Access: organization.id, public_user_data.user_id, role\n```\n\n## Supported Events (Full Catalog)\n\n**User**: `user.created` `user.updated` `user.deleted`\n\n**Session**: `session.created` `session.ended` `session.removed` `session.revoked`\n\n**Organization**: `organization.created` `organization.updated` `organization.deleted`\n\n**Organization Membership**: `organizationMembership.created` `organizationMembership.updated` `organizationMembership.deleted`\n\n**Organization Domain**: `organizationDomain.created` `organizationDomain.updated` `organizationDomain.deleted`\n\n**Organization Invitation**: `organizationInvitation.accepted` `organizationInvitation.created` `organizationInvitation.revoked`\n\n**Communication**: `email.created` `sms.created`\n\n**Waitlist**: `waitlistEntry.created` `waitlistEntry.updated`\n\n**Permission**: `permission.created` `permission.updated` `permission.deleted`\n\n**Role**: `role.created` `role.updated` `role.deleted`\n\n**Subscription**: `subscription.created` `subscription.updated` `subscription.active` `subscription.pastDue`\n\n**Subscription Item**: `subscriptionItem.created` `subscriptionItem.active` `subscriptionItem.updated` `subscriptionItem.canceled` `subscriptionItem.upcoming` `subscriptionItem.ended` `subscriptionItem.abandoned` `subscriptionItem.incomplete` `subscriptionItem.pastDue` `subscriptionItem.freeTrialEnding`\n\n**Payment**: `paymentAttempt.created` `paymentAttempt.updated`\n\n## Webhook Reliability\n\n**Retries**: Svix retries failed webhooks on a set schedule (see [Svix Retry Schedule](https:\u002F\u002Fdocs.svix.com\u002Fretries)). Return 2xx to succeed, 4xx\u002F5xx to retry. Use the `svix-id` header as an idempotency key to deduplicate retried events.\n\n**Replay**: Failed webhooks can be replayed from Dashboard.\n\n## Common Pitfalls\n\n| Symptom | Cause | Fix |\n|---------|-------|-----|\n| Verification fails (Next.js) | Wrong import or usage | Use `@clerk\u002Fnextjs\u002Fwebhooks`, pass `req` directly |\n| Verification fails (Express) | Using `express.json()` | Use `express.raw({ type: 'application\u002Fjson' })` for webhook route |\n| Route not found (404) | Wrong path | Use `\u002Fapi\u002Fwebhooks` or preserve existing path |\n| 401 or 404 on every delivery | `auth.protect()` covers the webhook route (in middleware or in the handler) | Remove that check; `verifyWebhook()` is the only check the route needs |\n| No data in DB | Async job pending | Wait\u002Fcheck logs |\n| Duplicate entries | Only handling `user.created` | Also handle `user.updated` |\n| Timeouts | Handler too slow | Queue async work, return 200 first |\n\n## Testing & Deployment\n\n**Local**: Use the Clerk CLI's first-party tunnel — no auth or linked project needed:\n\n```sh\nclerk webhooks listen --token \"$(clerk webhooks token)\" --forward-to http:\u002F\u002Flocalhost:3000\u002Fapi\u002Fwebhooks\n```\n\nAdd the printed relay URL (`https:\u002F\u002Fwebhooks.clerk.com\u002Fin\u002Fc_...\u002F`) as a webhook endpoint in the Dashboard — events don't flow until you do. `svix-*` headers are preserved, so `verifyWebhook()` works against that endpoint's signing secret as usual. Flags, offline signature checks (`clerk webhooks verify`), and agent-mode behavior are in the `clerk-cli` skill. Without the CLI, tunnel `localhost:3000` yourself (`ngrok`, `localtunnel`, `Cloudflare Tunnel`) and add the public URL to the Dashboard endpoint.\n\n**Production**: Update webhook endpoint URL to production domain. Copy `CLERK_WEBHOOK_SIGNING_SECRET` to production env vars.\n\n## References\n\n| Reference | Description |\n|-----------|-------------|\n| `references\u002Fframeworks.md` | Webhook handler examples for Express, Astro, Fastify, Nuxt, React Router, TanStack Start |\n\n## See Also\n\n- `clerk-cli` - `clerk webhooks listen`\u002F`verify` for local webhook testing\n- `clerk-setup` - Initial Clerk install\n- `clerk-orgs` - Org membership events\n- `clerk-billing` - Subscription, subscription item, and payment attempt events\n- `clerk-backend-api` - Sync via direct API calls","# Webhooks\n\nOutput complete, working webhook handlers with `verifyWebhook(req)` verification in every handler.\n\n## When to Use Webhooks\n\nWebhooks are **asynchronous and eventually consistent**. Delivery is fast but not guaranteed to be immediate, and may occasionally fail (Svix retries on a fixed schedule). Use them for:\n\n- Database sync (a separate users \u002F orgs table that follows Clerk)\n- Notifications (welcome emails, Slack pings, internal alerts)\n- Integrations triggered by lifecycle events\n\nDo NOT rely on webhook delivery as part of a synchronous flow such as onboarding (\"user signs up, then we read X from our DB\"). For data the user just created, read it from the [Clerk session token](https:\u002F\u002Fclerk.com\u002Fdocs\u002Fguides\u002Fsessions\u002Fsession-tokens) or call the Backend API directly. Webhooks fill the gap when you need data about *other* users or events the session token doesn't carry.\n\n## Verify Every Webhook\n\nUse `verifyWebhook(req)` from the framework-specific package (`@clerk\u002Fnextjs\u002Fwebhooks`, `@clerk\u002Fexpress\u002Fwebhooks`, etc.). It reads `CLERK_WEBHOOK_SIGNING_SECRET` automatically and throws on bad signatures. Skipping verification, even for notification-only handlers, exposes the endpoint to spoofed events.\n\n## Keep the Webhook Route Unprotected\n\nWebhook deliveries carry no user session. `verifyWebhook()` is the only check the route needs. A bare `clerkMiddleware()` protects nothing, so the route is already reachable. Don't call `auth.protect()` for `\u002Fapi\u002Fwebhooks(.*)`, in middleware or in the handler. A project that does returns `404` for every delivery until that call is removed. See [Ensure the webhook route is public](https:\u002F\u002Fclerk.com\u002Fdocs\u002Fguides\u002Fdevelopment\u002Fwebhooks\u002Fsyncing#ensure-the-webhook-route-is-public).\n\n## Complete Webhook Handler (Next.js App Router)\n\n```typescript\n\u002F\u002F app\u002Fapi\u002Fwebhooks\u002Froute.ts\nimport { verifyWebhook } from '@clerk\u002Fnextjs\u002Fwebhooks'\nimport { NextRequest } from 'next\u002Fserver'\nimport { db } from '@\u002Flib\u002Fdb'\n\nexport async function POST(req: NextRequest) {\n  \u002F\u002F ALWAYS verify - never skip, even for notification-only handlers\n  let evt\n  try {\n    evt = await verifyWebhook(req) \u002F\u002F uses CLERK_WEBHOOK_SIGNING_SECRET automatically\n  } catch (err) {\n    console.error('Webhook verification failed:', err)\n    return new Response('Verification failed', { status: 400 })\n  }\n\n  if (evt.type === 'user.created') {\n    const { id, email_addresses, first_name, last_name } = evt.data\n    const email = email_addresses[0]?.email_address\n    const name = `${first_name ?? ''} ${last_name ?? ''}`.trim()\n    await db.users.create({ data: { clerkId: id, email, name } })\n  }\n\n  if (evt.type === 'user.updated') {\n    const { id, email_addresses, first_name, last_name } = evt.data\n    const email = email_addresses[0]?.email_address\n    await db.users.update({ where: { clerkId: id }, data: { email, first_name, last_name } })\n  }\n\n  if (evt.type === 'user.deleted') {\n    const { id } = evt.data\n    await db.users.delete({ where: { clerkId: id } })\n  }\n\n  if (evt.type === 'organizationMembership.created') {\n    const { organization, public_user_data, role } = evt.data\n    const orgId = organization.id\n    const userId = public_user_data.user_id\n    await db.teamMembers.create({ data: { orgId, userId, role } })\n  }\n\n  if (evt.type === 'organizationMembership.deleted') {\n    const { organization, public_user_data } = evt.data\n    const orgId = organization.id\n    const userId = public_user_data.user_id\n    await db.teamMembers.delete({ where: { orgId_userId: { orgId, userId } } })\n  }\n\n  return new Response('OK', { status: 200 })\n}\n```\n\n## Full Example: Welcome Email (Resend) + Slack Notification on user.created\n\nNotification-only handlers still verify the signature. Same pattern as the database-sync handler:\n\n```typescript\n\u002F\u002F app\u002Fapi\u002Fwebhooks\u002Froute.ts\nimport { verifyWebhook } from '@clerk\u002Fnextjs\u002Fwebhooks'\nimport { NextRequest } from 'next\u002Fserver'\nimport { Resend } from 'resend'\n\nconst resend = new Resend(process.env.RESEND_API_KEY)\n\nexport async function POST(req: NextRequest) {\n  \u002F\u002F Step 1: ALWAYS verify the webhook signature - NEVER skip this\n  let evt\n  try {\n    evt = await verifyWebhook(req) \u002F\u002F uses CLERK_WEBHOOK_SIGNING_SECRET env var\n  } catch (err) {\n    console.error('Webhook verification failed:', err)\n    return new Response('Verification failed', { status: 400 })\n  }\n\n  \u002F\u002F Step 2: Listen for user.created event\n  if (evt.type === 'user.created') {\n    \u002F\u002F Step 3: Extract user email and name from webhook payload\n    const { id, email_addresses, first_name, last_name } = evt.data\n    const email = email_addresses[0]?.email_address\n    const name = `${first_name ?? ''} ${last_name ?? ''}`.trim()\n\n    \u002F\u002F Step 4: Call Resend API to send welcome email\n    await resend.emails.send({\n      from: 'noreply@yourdomain.com',\n      to: email,\n      subject: 'Welcome!',\n      html: `\u003Cp>Hi ${name}, welcome to our app!\u003C\u002Fp>`,\n    })\n\n    \u002F\u002F Step 5: Post notification to Slack channel\n    await fetch(process.env.SLACK_WEBHOOK_URL!, {\n      method: 'POST',\n      headers: { 'Content-Type': 'application\u002Fjson' },\n      body: JSON.stringify({\n        text: `New user signed up: ${name} (${email})`,\n      }),\n    })\n  }\n\n  \u002F\u002F Always return 200 to acknowledge receipt\n  return new Response('OK', { status: 200 })\n}\n```\n\n## Full Example: Organization Membership Sync to Database\n\n```typescript\n\u002F\u002F app\u002Fapi\u002Fwebhooks\u002Froute.ts\nimport { verifyWebhook } from '@clerk\u002Fnextjs\u002Fwebhooks'\nimport { NextRequest } from 'next\u002Fserver'\nimport { db } from '@\u002Flib\u002Fdb' \u002F\u002F your database client\n\nexport async function POST(req: NextRequest) {\n  \u002F\u002F ALWAYS verify signature - never skip, even for simple handlers\n  let evt\n  try {\n    evt = await verifyWebhook(req) \u002F\u002F uses CLERK_WEBHOOK_SIGNING_SECRET env var\n  } catch (err) {\n    console.error('Webhook verification failed:', err)\n    return new Response('Verification failed', { status: 400 })\n  }\n\n  if (evt.type === 'organization.created') {\n    const { id, name } = evt.data\n    await db.workspaces.create({\n      data: { orgId: id, name, createdAt: new Date() },\n    })\n  }\n\n  if (evt.type === 'organizationMembership.created') {\n    \u002F\u002F Extract organization ID, user ID, and role from payload\n    const { organization, public_user_data, role } = evt.data\n    const orgId = organization.id\n    const userId = public_user_data.user_id\n\n    \u002F\u002F Add to team_members table\n    await db.team_members.create({\n      data: { orgId, userId, role },\n    })\n\n    \u002F\u002F Create workspace record for new member\n    await db.workspaces.create({\n      data: { orgId, userId, createdAt: new Date() },\n    })\n  }\n\n  if (evt.type === 'organizationMembership.deleted') {\n    \u002F\u002F Extract organization ID and user ID from payload\n    const { organization, public_user_data } = evt.data\n    const orgId = organization.id\n    const userId = public_user_data.user_id\n\n    \u002F\u002F Remove from team_members table\n    await db.team_members.delete({\n      where: { orgId, userId },\n    })\n\n    \u002F\u002F Remove workspace record\n    await db.workspaces.deleteMany({\n      where: { orgId, userId },\n    })\n  }\n\n  \u002F\u002F Return 200 status on success\n  return new Response('OK', { status: 200 })\n}\n```\n\n## Other Frameworks\n\nFor Express, Astro, Fastify, Nuxt, React Router, and TanStack Start, use the framework-specific `verifyWebhook` adapter. Each Clerk SDK package ships its own (`@clerk\u002Fexpress\u002Fwebhooks`, `@clerk\u002Fastro\u002Fwebhooks`, `@clerk\u002Ffastify\u002Fwebhooks`, etc.).\n\nSee `references\u002Fframeworks.md` for full handler examples per framework.\n\n## Type Narrowing for `evt.data`\n\n`verifyWebhook` returns `WebhookEvent`, a discriminated union of all event types. Narrow with `evt.type` to get type-safe access to `evt.data`:\n\n```typescript\nconst evt = await verifyWebhook(req)\n\nif (evt.type === 'user.created') {\n  \u002F\u002F evt.data is now UserJSON, autocompletes id, email_addresses, etc.\n  console.log(evt.data.id)\n}\n```\n\nFor manual typing of nested payloads, import the JSON types from your framework's webhook subpath: `DeletedObjectJSON`, `EmailJSON`, `OrganizationInvitationJSON`, `OrganizationJSON`, `OrganizationMembershipJSON`, `SessionJSON`, `SMSMessageJSON`, `UserJSON`.\n\n## Payload Field Reference\n\n### User events (`user.created`, `user.updated`, `user.deleted`)\n```typescript\nconst {\n  id,                  \u002F\u002F Clerk user ID\n  email_addresses,     \u002F\u002F array; [0].email_address is primary email\n  first_name,\n  last_name,\n  image_url,\n  public_metadata,\n} = evt.data\n```\n\n### Organization events (`organization.created`, `organization.updated`, `organization.deleted`)\n```typescript\nconst {\n  id,    \u002F\u002F org ID\n  name,  \u002F\u002F org name\n  slug,\n} = evt.data\n```\n\n### Organization Membership events (`organizationMembership.created`, `organizationMembership.updated`, `organizationMembership.deleted`)\n```typescript\nconst {\n  organization,        \u002F\u002F { id, name, ... }\n  public_user_data,    \u002F\u002F { user_id, first_name, last_name, ... }\n  role,                \u002F\u002F e.g. 'org:admin', 'org:member'\n} = evt.data\n\u002F\u002F Access: organization.id, public_user_data.user_id, role\n```\n\n## Supported Events (Full Catalog)\n\n**User**: `user.created` `user.updated` `user.deleted`\n\n**Session**: `session.created` `session.ended` `session.removed` `session.revoked`\n\n**Organization**: `organization.created` `organization.updated` `organization.deleted`\n\n**Organization Membership**: `organizationMembership.created` `organizationMembership.updated` `organizationMembership.deleted`\n\n**Organization Domain**: `organizationDomain.created` `organizationDomain.updated` `organizationDomain.deleted`\n\n**Organization Invitation**: `organizationInvitation.accepted` `organizationInvitation.created` `organizationInvitation.revoked`\n\n**Communication**: `email.created` `sms.created`\n\n**Waitlist**: `waitlistEntry.created` `waitlistEntry.updated`\n\n**Permission**: `permission.created` `permission.updated` `permission.deleted`\n\n**Role**: `role.created` `role.updated` `role.deleted`\n\n**Subscription**: `subscription.created` `subscription.updated` `subscription.active` `subscription.pastDue`\n\n**Subscription Item**: `subscriptionItem.created` `subscriptionItem.active` `subscriptionItem.updated` `subscriptionItem.canceled` `subscriptionItem.upcoming` `subscriptionItem.ended` `subscriptionItem.abandoned` `subscriptionItem.incomplete` `subscriptionItem.pastDue` `subscriptionItem.freeTrialEnding`\n\n**Payment**: `paymentAttempt.created` `paymentAttempt.updated`\n\n## Webhook Reliability\n\n**Retries**: Svix retries failed webhooks on a set schedule (see [Svix Retry Schedule](https:\u002F\u002Fdocs.svix.com\u002Fretries)). Return 2xx to succeed, 4xx\u002F5xx to retry. Use the `svix-id` header as an idempotency key to deduplicate retried events.\n\n**Replay**: Failed webhooks can be replayed from Dashboard.\n\n## Common Pitfalls\n\n| Symptom | Cause | Fix |\n|---------|-------|-----|\n| Verification fails (Next.js) | Wrong import or usage | Use `@clerk\u002Fnextjs\u002Fwebhooks`, pass `req` directly |\n| Verification fails (Express) | Using `express.json()` | Use `express.raw({ type: 'application\u002Fjson' })` for webhook route |\n| Route not found (404) | Wrong path | Use `\u002Fapi\u002Fwebhooks` or preserve existing path |\n| 401 or 404 on every delivery | `auth.protect()` covers the webhook route (in middleware or in the handler) | Remove that check; `verifyWebhook()` is the only check the route needs |\n| No data in DB | Async job pending | Wait\u002Fcheck logs |\n| Duplicate entries | Only handling `user.created` | Also handle `user.updated` |\n| Timeouts | Handler too slow | Queue async work, return 200 first |\n\n## Testing & Deployment\n\n**Local**: Use the Clerk CLI's first-party tunnel — no auth or linked project needed:\n\n```sh\nclerk webhooks listen --token \"$(clerk webhooks token)\" --forward-to http:\u002F\u002Flocalhost:3000\u002Fapi\u002Fwebhooks\n```\n\nAdd the printed relay URL (`https:\u002F\u002Fwebhooks.clerk.com\u002Fin\u002Fc_...\u002F`) as a webhook endpoint in the Dashboard — events don't flow until you do. `svix-*` headers are preserved, so `verifyWebhook()` works against that endpoint's signing secret as usual. Flags, offline signature checks (`clerk webhooks verify`), and agent-mode behavior are in the `clerk-cli` skill. Without the CLI, tunnel `localhost:3000` yourself (`ngrok`, `localtunnel`, `Cloudflare Tunnel`) and add the public URL to the Dashboard endpoint.\n\n**Production**: Update webhook endpoint URL to production domain. Copy `CLERK_WEBHOOK_SIGNING_SECRET` to production env vars.\n\n## References\n\n| Reference | Description |\n|-----------|-------------|\n| `references\u002Fframeworks.md` | Webhook handler examples for Express, Astro, Fastify, Nuxt, React Router, TanStack Start |\n\n## See Also\n\n- `clerk-cli` - `clerk webhooks listen`\u002F`verify` for local webhook testing\n- `clerk-setup` - Initial Clerk install\n- `clerk-orgs` - Org membership events\n- `clerk-billing` - Subscription, subscription item, and payment attempt events\n- `clerk-backend-api` - Sync via direct API calls",{"name":5,"license":15,"metadata":24,"description":7,"allowed-tools":27,"compatibility":28},{"author":25,"version":26},"clerk","1.2.0","WebFetch","Requires CLERK_WEBHOOK_SIGNING_SECRET (svix signing secret from Clerk dashboard)","master","d98539ce2a8653654e97b8af9cef89366e90e157",".agents\u002Fskills\u002Fclerk-webhooks","https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo\u002FHaki-Soft","https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo","CS student | Cloud Computing | Dev full stack","2026-10-17 23:57:15",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add Sebastian-Tunjuelo\u002FHaki-Soft --skill clerk-webhooks",{"tool":42,"command":43},"bunx","bunx skills add Sebastian-Tunjuelo\u002FHaki-Soft --skill clerk-webhooks",{"tool":45,"command":46},"pnpm","pnpm dlx skills add Sebastian-Tunjuelo\u002FHaki-Soft --skill clerk-webhooks","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo\u002FHaki-Soft\u002Fblob\u002Fmaster\u002F.agents\u002Fskills\u002Fclerk-webhooks\u002FSKILL.md",true,[50,56],{"path":51,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":54,"sourceHtmlUrl":55},"evals\u002Fevals.json","REFERENCE","参考文档",3843,"https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo\u002FHaki-Soft\u002Fblob\u002Fmaster\u002F.agents\u002Fskills\u002Fclerk-webhooks\u002Fevals\u002Fevals.json",{"path":57,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":58,"sourceHtmlUrl":59},"references\u002Fframeworks.md",6374,"https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo\u002FHaki-Soft\u002Fblob\u002Fmaster\u002F.agents\u002Fskills\u002Fclerk-webhooks\u002Freferences\u002Fframeworks.md",[61,70,76,83,90,97],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":65,"licenseFileUrl":66,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":19},"01M7EZT4B6P7092XSTRDM57FKJ","frontend-design","Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.","Apache-2.0","https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo\u002FHaki-Soft\u002Fblob\u002Fmaster\u002F.kiro\u002Fskills\u002Ffrontend-design\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo\u002FHaki-Soft\u002Fblob\u002Fmaster\u002F.kiro\u002Fskills\u002Ffrontend-design\u002FSKILL.md",[],[],{"skillNo":71,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":65,"licenseFileUrl":72,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M7EZRDK45BCJY93D2PKT5SPH","https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo\u002FHaki-Soft\u002Fblob\u002Fmaster\u002F.claude\u002Fskills\u002Ffrontend-design\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo\u002FHaki-Soft\u002Fblob\u002Fmaster\u002F.claude\u002Fskills\u002Ffrontend-design\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M7EZQYC1X9EHWMNXRH19HGNW","vercel-react-best-practices","React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React\u002FNext.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.","https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo\u002FHaki-Soft\u002Fblob\u002Fmaster\u002F.agents\u002Fskills\u002Fvercel-react-best-practices\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M7EZPK5SY4GPRAA7CZC57NBX","prisma-orm-setup","Set up Prisma ORM in an application, connect its database, or troubleshoot the connection of an existing Prisma 6, 7, or 8 app. Defaults new applications to Prisma ORM 8 and loads the package-owned prisma-8 skill; keeps existing Prisma 6\u002F7 apps on their version with provider references for PostgreSQL, MySQL, SQLite, SQL Server, CockroachDB, MongoDB, and Prisma Postgres.","https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo\u002FHaki-Soft\u002Fblob\u002Fmaster\u002F.agents\u002Fskills\u002Fprisma-orm-setup\u002FSKILL.md",[],[],{"skillNo":91,"name":92,"nameZh":6,"description":93,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":19},"01M7EZPG8PYGA9CB5YYVQC8PKS","prisma-database-setup","Deprecated compatibility name for prisma-orm-setup. Use only when a user or existing integration explicitly invokes prisma-database-setup; otherwise select prisma-orm-setup.","https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo\u002FHaki-Soft\u002Fblob\u002Fmaster\u002F.agents\u002Fskills\u002Fprisma-database-setup\u002FSKILL.md",[],[],{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":19},"01M7EZPBX5S872Y2WP1RRFDC6V","prisma-client-api","Prisma Client API reference covering model queries, filters, operators, and client methods. Use when writing database queries, using CRUD operations, filtering data, or configuring Prisma Client. Triggers on \"prisma query\", \"findMany\", \"create\", \"update\", \"delete\", \"$transaction\".","https:\u002F\u002Fgithub.com\u002FSebastian-Tunjuelo\u002FHaki-Soft\u002Fblob\u002Fmaster\u002F.agents\u002Fskills\u002Fprisma-client-api\u002FSKILL.md",[],[]]