---
title: "Register webhooks"
description: "One call mounts every inbound route on the deployment: the auth routes, the billing and email webhooks with their signatures verified once, the metered AI stream and the health check. Then point Polar and Resend at them and read the delivery log."
canonical_url: "https://nuxt-backend.dev/docs/ship/security/webhooks"
---
# Register webhooks

> One call mounts every inbound route on the deployment: the auth routes, the billing and email webhooks with their signatures verified once, the metered AI stream and the health check. Then point Polar and Resend at them and read the delivery log.

Version: nuxt-backend 0.6.x · Tab: Ship · Kind: how-to · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [API reference](https://nuxt-backend.dev/docs/reference/api/http)
- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/convex/components/backend/webhooks.ts)

One call mounts every route your backend answers over HTTP, so billing and email events reach it, signed, with nothing else to wire. `registerBackendRoutes(http, options)` from `nuxt-backend/http` mounts them on your Convex HTTP router: the auth routes, the two webhooks, the metered AI stream and the health check. Both webhooks verify their signature once, at one edge, with one verifier ([Webhooks: fail closed](https://nuxt-backend.dev/docs/ship/security#webhooks-fail-closed)). Each option takes the instance its `setup*` helper returns. This is the scaffolded `http.ts`, its comment left out:

```ts [backend/http.ts]
import { registerBackendRoutes } from 'nuxt-backend/http'
import { httpRouter } from 'convex/server'
import { ai } from './ai'
import { authComponent, createAuth } from './auth'
import { billing } from './billing'
import { email } from './email'

const http = httpRouter()
registerBackendRoutes(http, {
  auth: { authComponent, createAuth },
  billing,
  email,
  ai,
})

export default http
```

## What gets mounted

<table>
<thead>
  <tr>
    <th>
      Route
    </th>
    
    <th>
      What it does
    </th>
    
    <th>
      Verified with
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Auth routes
    </td>
    
    <td>
      The Better Auth HTTP endpoints (same as <code>
        authComponent.registerRoutes
      </code>
      
      )
    </td>
    
    <td>
      Auth's own signing
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        /billing/events
      </code>
      
       (POST)
    </td>
    
    <td>
      Refreshes the reactive entitlement cache (subscriptions, benefit grants, credit balances) and fulfils <a href="https://nuxt-backend.dev/docs/build/growth/offers/gifts">
        gift purchases
      </a>
    </td>
    
    <td>
      <code>
        BILLING_WEBHOOK_SECRET
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        /email/events
      </code>
      
       (POST)
    </td>
    
    <td>
      Tracks delivery status (delivered / bounced / complained) behind <code>
        useEmailStatus
      </code>
    </td>
    
    <td>
      <code>
        EMAIL_WEBHOOK_SECRET
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        /ai/stream
      </code>
      
       (POST + OPTIONS)
    </td>
    
    <td>
      Runs an <code>
        ai.stream(...)
      </code>
      
       handler and streams its chunks to <code>
        useAiStream
      </code>
      
      . The OPTIONS route answers the browser's CORS preflight for the app origin (<code>
        SITE_URL
      </code>
      
      )
    </td>
    
    <td>
      The <code>
        streamId
      </code>
      
       the signed-in <code>
        start
      </code>
      
       action handed the caller (its credits are already reserved)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        /backend/health
      </code>
      
       (GET)
    </td>
    
    <td>
      The <a href="https://nuxt-backend.dev/docs/ship/operate/monitoring#the-health-endpoint">
        health check
      </a>
      
       the app's <code>
        /api/backend/health
      </code>
      
       asks, at a fixed path
    </td>
    
    <td>
      Public for each capability's state; the detail for an administrator
    </td>
  </tr>
</tbody>
</table>

Both webhooks share one fail-closed policy: missing secret → `503`, invalid signature → `403`, oversized body → `413`, authentic-but-unknown event type → `202`, handler throw → `500` (so the provider retries), redelivery of a processed id → `200`. Every delivery's outcome lands in the component's [delivery log](#the-delivery-log) (the Backend tab in Nuxt DevTools and the admin console's Webhooks tab read it). Both routes run through one edge, so the policy cannot drift between them. The size cap is 1 MiB, counted in bytes: a `Content-Length` over it is refused before the body is read. A refused request also leaves a `webhook.rejected` line in the deployment log, with the route, the outcome and the status, once per isolate for each route and outcome so junk traffic cannot flood the log; a missing secret leaves `webhook.secret_missing` instead. [Troubleshooting](https://nuxt-backend.dev/docs/ship/operate/troubleshooting#log-codes) says what to do about each.

## Point the provider dashboards at them

Webhooks arrive on your backend's **site** URL: the `.convex.site` domain, not `.convex.cloud` (inside the deployment the platform runtime exposes it as `CONVEX_SITE_URL`):

- **Billing (Polar).** `npx nuxt-backend billing sync` (with `--env production` for production) provisions the endpoint at `https://your-deployment.convex.site/billing/events`, subscribed to every event the package handles, and stores its secret on the deployment as `BILLING_WEBHOOK_SECRET`. By hand: the provider's dashboard, Settings, Webhooks, with the same secret on the deployment.
- **Email (Resend).** `npx nuxt-backend email sync` (with `--prod` for production) points a webhook at `https://your-deployment.convex.site/email/events` and stores its secret as `EMAIL_WEBHOOK_SECRET`. By hand: the provider's dashboard, Webhooks, subscribed to the `email.*` events.

A local deployment has no public URL, so no provider reaches it. Develop on a cloud dev deployment, or run a tunnel to the local one ([Develop on real sandboxes](https://nuxt-backend.dev/docs/develop/sandboxes)). Resend's test addresses then send real delivery events, and Polar's sandbox real billing events. [Service map](https://nuxt-backend.dev/docs/services#provider-setup) has both providers per environment, with the findings that check them.

## Reacting to events

The built-in handlers keep state fresh; your hooks run on top of them, per event.

Billing hooks go on `setupBilling` and run after the built-in entitlement refresh: see [React to billing events](https://nuxt-backend.dev/docs/build/billing/events).

Email hooks go on [`setupEmail`](https://nuxt-backend.dev/docs/build/email/sending), keyed by the provider's event names too (`'email.delivered'`, `'email.bounced'` and the rest of the catalog on [Delivery tracking](https://nuxt-backend.dev/docs/build/email/delivery#reacting-to-events)), and fire after the event is verified and the status recorded:

```ts [backend/email.ts]
export const email = setupEmail(components, {
  events: {
    'email.delivered': async (ctx, event) => { /* … */ },
    'email.bounced': async (ctx, event) => { /* suppress future sends to event.data.to */ },
    'email.complained': async (ctx, event) => { /* alert an admin */ },
  },
})
```

## The delivery log

Redelivery dedupe reads the log, and how it keeps an outcome depends on whether the request proved who sent it:

- A delivery whose signature verified (`ok`, `unknown_type`, `handler_error`) gets a row of its own. The newest 200 are kept: older rows are trimmed in the background, at most once an hour, so recording a delivery never reads the rest of the log and concurrent deliveries never wait on each other.
- A request answered before any signature verified (`missing_secret`, `oversized`, `invalid_signature`, or a `duplicate` of a processed id) is counted per route and outcome instead, under the latest one's delivery id. Anyone can POST to these routes, so a flood of junk can neither grow the log nor push out the verified rows that dedupe relies on. A count starts afresh after a day without one.

Delivery ids and event types are kept to their first 128 characters, a handler's error note to its first 500.

The log spans every account on the deployment, so `getWebhookDeliveries` (re-exported by the scaffolded `webhooks.ts`, from `setupWebhooks`) is admin-tier: it answers an administrator in person (an account with the `admin` role, read fresh, or one `adminUserIds` names) and `null` to anyone else, signed out included. The DevTools Backend tab and the admin console's Webhooks tab say so instead of showing an empty log.

A delivery that failed is sent again by its provider, which retries on a `5xx`. After a fix, [Replay a webhook delivery](https://nuxt-backend.dev/docs/ship/operate/replay) asks the provider to send it again from the log, in the admin console and in DevTools. [Respond to incidents](https://nuxt-backend.dev/docs/ship/operate/runbooks#webhooks-fail) says what to check first.

## Custom paths

Change where the routes mount with `billingPath`, `emailPath` and `aiPath`, and point the provider dashboards at the new paths:

```ts [backend/http.ts]
registerBackendRoutes(http, {
  auth: { authComponent, createAuth },
  billing,
  email,
  ai,
  billingPath: '/hooks/billing',
  emailPath: '/hooks/email',
})
```

<note>

Every part is required. A route left out would answer `404` the first time a provider or a client calls it, so the type refuses the call instead. For fully custom routing, skip `registerBackendRoutes` and mount each part on your own router: `authComponent.registerRoutes(http, createAuth)` for the auth routes; each instance's `webhookHandler` (`billing`, `email`), wrapped in `httpActionGeneric` from `convex/server`; and `ai.httpHandler`, already an HTTP action, beside an `OPTIONS` route that answers its CORS preflight.

</note>

## Related

- [Service map](https://nuxt-backend.dev/docs/services#provider-setup): both providers' webhooks, per environment.
- [Replay a webhook delivery](https://nuxt-backend.dev/docs/ship/operate/replay): send a failed delivery again from the log.
- [React to billing events](https://nuxt-backend.dev/docs/build/billing/events) and [Delivery tracking](https://nuxt-backend.dev/docs/build/email/delivery): the hooks that run on top.
- [HTTP routes](https://nuxt-backend.dev/docs/reference/backend/http-routes): every route on the deployment and in the app.
- [Security model](https://nuxt-backend.dev/docs/ship/security#webhooks-fail-closed): why the routes fail closed.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
