clerk-webhooks
БесплатноБез исполняемых скриптовНе проверенClerk webhooks for real-time events and data syncing. Verify with verifyWebhook from the framework-specific package. Handle user, session, organization…
от vvedantb★ 100 звёзд на GitHubОб этом скилле
Webhooks
Output complete, working webhook handlers with verifyWebhook(req) verification in every handler.
When to Use Webhooks
Webhooks 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:
- Database sync (a separate users / orgs table that follows Clerk)
- Notifications (welcome emails, Slack pings, internal alerts)
- Integrations triggered by lifecycle events
Do 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 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.
Verify Every Webhook
Use verifyWebhook(req) from the framework-specific package (@clerk/nextjs/webhooks, @clerk/express/webhooks, 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.
Make the Webhook Route Public
Webhook routes must be excluded from Clerk middleware protection. Without this, Clerk returns 401.
// proxy.ts (Next.js <=15: middleware.ts)
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
const isPublicRoute = createRouteMatcher(["/api/webhooks(.*)"]);
export default clerkMiddleware(async (auth, req) => {
if (!isPublicRoute(req)) await auth.protect();
});
Complete Webhook Handler (Next.js App Router)
// app/api/webhooks/route.ts
import { verifyWebhook } from "@clerk/nextjs/webhooks";
import { NextRequest } from "next/server";
import { db } from "@/lib/db";
export async function POST(req: NextRequest) {
// ALWAYS verify - never skip, even for notification-only handlers
let evt;
try {
evt = await verifyWebhook(req); // uses CLERK_WEBHOOK_SIGNING_SECRET automatically
} catch (err) {
console.error("Webhook verification failed:", err);
return new Response("Verification failed", { status: 400 });
}
if (evt.type === "user.created") {
const { id, email_addresses, first_name, last_name } = evt.data;
const email = email_addresses[0]?.email_address;
const name = `${first_name ?? ""} ${last_name ?? ""}`.trim();
await db.users.create({ data: { clerkId: id, email, name } });
}
if (evt.type === "user.updated") {
const { id, email_addresses, first_name, last_name } = evt.data;
const email = email_addresses[0]?.email_address;
await db.users.update({
where: { clerkId: id },
data: { email, first_name, last_name },
});
}
if (evt.type === "user.deleted") {
const { id } = evt.data;
await db.users.delete({ where: { clerkId: id } });
}
if (evt.type === "organizationMembership.created") {
const { organization, public_user_data, role } = evt.data;
const orgId = organization.id;
const userId = public_user_data.user_id;
await db.teamMembers.create({ data: { orgId, userId, role } });
}
if (evt.type === "organizationMembership.deleted") {
const { organization, public_user_data } = evt.data;
const orgId = organization.id;
const userId = public_user_data.user_id;
await db.teamMembers.delete({ where: { orgId_userId: { orgId, userId } } });
}
return new Response("OK", { status: 200 });
}
Full Example: Welcome Email (Resend) + Slack Notification on user.created
Notification-only handlers still verify the signature. Same pattern as the database-sync handler:
// app/api/webhooks/route.ts
import { verifyWebhook } from "@clerk/nextjs/webhooks";
import { NextRequest } from "next/server";
import { Resend } from "resend";
const resend = new Resend(process.env.RESEND_API_KEY);
export async function POST(req: NextRequest) {
// Step 1: ALWAYS verify the webhook signature - NEVER skip this
let evt;
try {
evt = await verifyWebhook(req); // uses CLERK_WEBHOOK_SIGNING_SECRET env var
} catch (err) {
console.error("Webhook verification failed:", err);
return new Response("Verification failed", { status: 400 });
}
// Step 2: Listen for user.created event
if (evt.type === "user.created") {
// Step 3: Extract user email and name from webhook payload
const { id, email_addresses, first_name, last_name } = evt.data;
const email = email_addresses[0]?.email_address;
const name = `${first_name ?? ""} ${last_name ?? ""}`.trim();
// Step 4: Call Resend API to send welcome email
await resend.emails.send({
from: "[email protected]",
to: email,
subject: "Welcome!",
html: `<p>Hi ${name}, welcome to our app!</p>`,
});
// Step 5: Post notification to Slack channel
await fetch(process.env.SLACK_WEBHOOK_URL!, {
meth
Установить clerk-webhooks в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
WebFetchВложенные файлы
FAQ
Что делает скилл clerk-webhooks?
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.
Как установить скилл clerk-webhooks?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл clerk-webhooks запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic