Skip to Content

Better Auth plugin

Let signed-in users manage their own webhook endpoints through authenticated routes, stored in your existing Better Auth database.

The goodWebhooks plugin lets signed-in users manage their own webhook endpoints in your app. It adds one model and nine authenticated routes to your Better Auth instance and stores endpoints with your existing database adapter. To see it work first, run the Better Auth quick start. To build the full flow in an app, follow the tutorial.

The plugin manages endpoints only; it sends nothing. To send events, add the built-in delivery or a custom sender.

Install

npm install good-webhooks better-auth@1.7.10

Supports Better Auth >=1.7.7 <1.8.0 || >=1.8.0-beta.0 <1.9.0-0: 1.7.7 or later in 1.7, and 1.8 including the 1.8.0 betas.

Add the server plugin

auth.ts
import { betterAuth } from 'better-auth'
import { goodWebhooks } from 'good-webhooks/better-auth'
import { eventTypes } from './event-types.js'

export const auth = betterAuth({
  database, // your existing database or adapter
  secret: process.env.BETTER_AUTH_SECRET!,
  plugins: [goodWebhooks({ eventTypes })], 
})
event-types.ts
export const eventTypes = ['invoice.created', 'invoice.paid'] as const

Keep the tuple in its own module so the browser can import it without server code. as const carries the literal names into the client types. Routes appear under your auth handler's base path, for example POST /api/auth/good-webhooks/create.

Generate and apply the schema

Use Better Auth's CLI at your installed version:

npx auth@1.7.10 migrate --config ./src/auth.ts   # built-in SQL adapters
npx auth@1.7.10 generate --config ./src/auth.ts  # Drizzle or Prisma, then run their migrations

Keep every generated field and the unique allocationKey index; it enforces the per-scope endpoint limit under concurrent creates. Run the same command again after upgrading Good Webhooks to a release that adds fields, such as 0.2.0, which adds pauseReason. Do not apply Good Webhooks' management.sql here: that file is for the standalone PostgreSQL provider.

Add the client plugin

auth-client.ts
import { createAuthClient } from 'better-auth/client'
import { goodWebhooksClient } from 'good-webhooks/better-auth/client'
import { eventTypes } from './event-types.js'

export const authClient = createAuthClient({
  plugins: [goodWebhooksClient({ eventTypes })],
})

Use it

const { data, error } = await authClient.goodWebhooks.create({
  url: 'https://receiver.example/webhooks',
  eventTypes: ['invoice.paid'],
})
data?.secret // show once, then never again
data?.endpoint.id

const endpoints = await authClient.goodWebhooks.list({})

An omitted scope means the signed-in user. Only create and rotate responses include the signing secret. Create and update also accept headers: extra request headers sent on every delivery and test event, for example an API gateway key. Reads return them, {} when there are none. See send extra headers.

Options

OptionDefault
eventTypesrequired
authorizeScopedeny
allowLocalhostfalse
maxEndpoints1,000 per scope
schema.modelNamewebhookEndpoint
schema.fields
  • eventTypes: configured event names. Pass a literal tuple for typed clients.
  • authorizeScope: policy for application scope and custom scope types. See permissions.
  • allowLocalhost: permit HTTP loopback URLs in development.
  • maxEndpoints: (scope) => number | Promise<number> from 0 to 1,000. Lower the endpoint limit per scope.
  • schema.modelName: rename the model. Not a PostgreSQL namespace.
  • schema.fields: rename individual fields.

Regenerate and apply the schema after changing schema. Your Better Auth database or ORM configuration decides where the model lives. The plugin reference has every route and error.

Supported databases

The plugin stores endpoints through Better Auth's public adapter interface. On Node.js 24, with Better Auth 1.7.7 and the newest 1.7 and 1.8 releases, a weekly CI run tests it against real SQLite, PostgreSQL 16, MySQL 8.4, MongoDB 8, SQL Server 2022, libSQL, and Cloudflare D1 (local Miniflare) databases, and through Drizzle and Prisma on PostgreSQL. Each run covers concurrent creates at the endpoint limit, revision-guarded updates, and maximum-length Unicode values.

SQL Server needs a UTF-8 collation

Better Auth generates varchar columns, so a non-UTF-8 collation corrupts Unicode scope IDs, URLs, and descriptions. CI uses Latin1_General_100_CI_AS_SC_UTF8.

Bun's SQLite, hosted D1, remote Turso, MongoDB replica-set transactions, and Drizzle or Prisma on other databases are untested.

On this page