@brianmmdev/clerk-webhooks-handler

中文文档
1.0.7发布于 2025/04/05ISCCommonJS近 30 天下载 3991

A package to streamline the configuration of Clerk webhooks in a Next.js application.

原始使用文档
文档目录6 节
  1. Project goals
  2. Installation
  3. Environment Variables
  4. Usage/Examples
  5. Contributing
  6. Feedback

Clerk Webhooks Handler

A package to streamline the configuration of Clerk webhooks.

⚠ This project is not officially supported by Clerk. Use at your own discretion.

Project goals

The goal of this package is to make it easier to work with Clerk webhooks by abstracting away the process of parsing the incoming event type and payload, as well as automatically validating the signature of the incoming request.

The result is a single method that uses callback functions and passes through fully-typed versions of the supported payloads, making it simpler to perform operations such as updating database records, sending custom notifications, and any other custom logic that you'd like to build.

Installation

This package is deployed to NPM and can be installed with the following command:

npm install @brianmmdev/clerk-webhooks-handler

Environment Variables

To run this project, you will need to add the following environment variables to your .env file:

  • WEBHOOK_SECRET — The Signing Secret value obtained from the Clerk dashboard when registering a new endpoint.

Usage/Examples

While this package can theoretically be used with any JavaScript web framework, it has only been tested with Next.js as of now, so this example will be using Next.js.

  1. Create a route handler at your preferred location.
  2. Create an instance of createWebhooksHandler, passing in a configuration object with a series of callback functions.
  3. Export the handler's POST method as POST so Next.js will pass web requests into it.

The following example shows what this route handler would look like with the onUserUpdated which fires when a user is updated in Clerk, and onSessionCreated when a session is created.

import { createWebhooksHandler } from "@brianmmdev/clerk-webhooks-handler";
import { UserJSON, SessionJSON } from "@clerk/nextjs/server";

const handler = createWebhooksHandler({
  // Add/remove optional handlers to get access to the data.
  onUserUpdated: async (payload: UserJSON) => {
    // Handle the payload...
  },
  onSessionCreated: async (payload: SessionJSON) => {
    // Handle the payload...
  }
})

export const POST = handler.POST

The WebhookRegistrationConfig object defines all supported callbacks, which in turn correspond to their webhook event in Clerk:

export type WebhookRegistrationConfig = {
  secret?: string
  onEmailCreated?: HandlerFn<EmailJSON>;
  onOrganizationCreated?: HandlerFn<OrganizationJSON>;
  onOrganizationDeleted?: HandlerFn<DeletedObjectJSON>;
  onOrganizationUpdated?: HandlerFn<OrganizationJSON>;
  onOrganizationInvitationAccepted?: HandlerFn<OrganizationInvitationJSON>;
  onOrganizationInvitationCreated?: HandlerFn<OrganizationInvitationJSON>;
  onOrganizationInvitationRevoked?: HandlerFn<OrganizationInvitationJSON>;
  onOrganizationMembershipCreated?: HandlerFn<OrganizationMembershipJSON>;
  onOrganizationMembershipDeleted?: HandlerFn<DeletedObjectJSON>;
  onOrganizationMembershipUpdated?: HandlerFn<OrganizationMembershipJSON>;
  onPermissionCreated?: HandlerFn<PermissionJSON>;
  onPermissionDeleted?: HandlerFn<DeletedObjectJSON>;
  onPermissionUpdated?: HandlerFn<PermissionJSON>;
  onRoleCreated?: HandlerFn<RoleJSON>;
  onRoleDeleted?: HandlerFn<DeletedObjectJSON>;
  onRoleUpdated?: HandlerFn<RoleJSON>;
  onSessionCreated?: HandlerFn<SessionJSON>;
  onSessionEnded?: HandlerFn<SessionJSON>;
  onSessionPending?: HandlerFn<SessionJSON>;
  onSessionRemoved?: HandlerFn<SessionJSON>;
  onSessionRevoked?: HandlerFn<SessionJSON>;
  onSmsCreated?: HandlerFn<SMSMessageJSON>;
  onUserCreated?: HandlerFn<UserJSON>;
  onUserCreatedAtEdge?: HandlerFn<UserJSON>;
  onUserDeleted?: HandlerFn<DeletedObjectJSON>;
  onUserUpdated?: HandlerFn<UserJSON>;
  onWaitlistEntryCreated?: HandlerFn<OrganizationJSON>;
  onWaitlistEntryUpdated?: HandlerFn<OrganizationJSON>;
}

In the event that a callback is not defined for the corresponding webhook, the package will respond with a 404 status to the caller.

Contributing

Contributions are always welcome! To contribute to this project, fork it into your own GitHub account or organization, make the necessary changes, and create a pull request into this repository.

If I do not respond in a timely manner, feel free to ping or DM me on Twitter: @brianmmdev

Feedback

If you have any feedback, please reach out to me on Twitter: @brianmmdev

To report issues or suggest improvements, feel free to create an issue.

版本与发布记录

@brianmmdev/clerk-webhooks-handler 共发布 8 个版本,首次发布于 2024/05/01;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.7latest2025/04/051.6 年前
1.0.62025/02/081.7 年前
1.0.52024/05/112 年前
1.0.42024/05/032 年前
1.0.32024/05/012 年前
1.0.22024/05/012 年前

关于 @brianmmdev/clerk-webhooks-handler 的常见问题

@brianmmdev/clerk-webhooks-handler 是什么?

A package to streamline the configuration of Clerk webhooks in a Next.js application.

如何安装 @brianmmdev/clerk-webhooks-handler?

在项目目录运行 npm install @brianmmdev/clerk-webhooks-handler,或使用 pnpm add / yarn add / bun add。

@brianmmdev/clerk-webhooks-handler 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/brianmmdev__clerk-webhooks-handler 是否存在。

@brianmmdev/clerk-webhooks-handler 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@brianmmdev/clerk-webhooks-handler 可以商用吗?

@brianmmdev/clerk-webhooks-handler 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@brianmmdev/clerk-webhooks-handler 的下载量有多少?

根据 npm 官方下载统计,@brianmmdev/clerk-webhooks-handler 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,991 次,日均约 133 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@brianmmdev/clerk-webhooks-handler 还在维护吗?

最新版本 1.0.7 发布于 2025/04/05(1.6 年前);至今共发布 8 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/05/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。