# Stop Bad Emails at Clerk Sign-up

URL: https://email-validation.org/docs/guides/clerk/
Updated: 2026-11-27

> Documentation index: https://email-validation.org/llms.txt

Keep sign-ups with bad email addresses out of an app that uses Clerk. A small file you add to your server checks
each new user's address with the API. When the result is a status you chose to stop (by default `invalid` and
`disposable`), it flags the account so your app can keep it out, or, if you choose, bans or deletes it. If the API
is slow or down, the sign-up goes through.

It is one TypeScript file with no dependencies. Download it: [email-validation-clerk.ts](https://email-validation.org/downloads/clerk/email-validation-clerk.ts). It runs on Next.js, Remix, Hono, Express,
Bun, Deno, Cloudflare Workers and Node 22 or later.

## How it works, and its limits

Clerk has no hook that runs before it creates a user, and it sends its webhooks after the account exists. So the
file has two parts:

- **A webhook handler** for Clerk's `user.created` event. It works with Clerk's prebuilt `<SignUp />`, with social
  sign-ups and with users created through Clerk's API. The account exists until the webhook arrives
  (usually seconds; Clerk does not guarantee a time). Then the handler **flags** it (the default), or **bans** or **deletes** it if you choose that.
- **A server-side check** for a custom sign-up flow. Call it before `signUp.create()` and a stopped address never
  becomes an account. Someone who calls Clerk's API directly skips your form, and so skips this check, so keep the
  webhook handler as well.

If your Clerk app requires email verification, a person who cannot receive mail at the address never finishes
signing up. `invalid` then matters mostly for social sign-ups and users created through the API, and `disposable`
for everyone. Clerk's own "Block disposable email addresses" protection can run alongside this one.

Only the address an account is created with is checked. An address the user adds or makes primary later is not.

## Set it up

This is code for your app's server, added by whoever builds your app: there is no browser-only option. You can
read the file in your browser before you add it.

1. Create an API key on the [API keys page](https://email-validation.org/app/api-keys/) with the permission **Validate addresses** and a
   [daily credit cap](https://email-validation.org/docs/authentication/#limits). Put it in the server variable `EV_API_KEY`, never in browser
   code.
2. Copy `email-validation-clerk.ts` into your app, for example to `lib/`.
3. Add a route. In the Next.js App Router, that is `app/api/webhooks/clerk/route.ts`:

   ```ts
   import { createClerkSignupHook } from '@/lib/email-validation-clerk';

   export const POST = createClerkSignupHook({
     apiKey: process.env.EV_API_KEY,
     signingSecret: process.env.CLERK_WEBHOOK_SIGNING_SECRET,
     clerkSecretKey: process.env.CLERK_SECRET_KEY,
   });
   ```

   Leave `/api/webhooks(.*)` out of the routes `clerkMiddleware()` protects. Clerk signs every delivery, and the
   handler refuses any it cannot verify.
4. In the Clerk Dashboard, go to **Webhooks** → **Add Endpoint**. Enter `https://<your app>/api/webhooks/clerk`,
   pick the event `user.created`, then copy the endpoint's signing secret into `CLERK_WEBHOOK_SIGNING_SECRET`.
5. Keep flagged accounts out: where your app loads the signed-in user on the server, read the flag (skip this
   step if you chose `ban` or `delete`):

   ```ts
   import { auth, clerkClient } from '@clerk/nextjs/server';
   import type { EmailValidationMetadata } from '@/lib/email-validation-clerk';

   const { userId } = await auth();
   const user = userId ? await (await clerkClient()).users.getUser(userId) : null;
   const flag = user?.publicMetadata?.email_validation as EmailValidationMetadata | undefined;
   if (flag?.stopped) {
     // ask for another address, or sign the user out
   }
   ```

6. Test it: in the Clerk Dashboard, go to **Users** → **Create user** and use a [test address](https://email-validation.org/docs/test-addresses/)
   such as `disposable@sandbox.email-validation.org`. It is free and always answers `disposable`, so you can see the
   account get flagged. Test addresses receive no mail, so do not sign up with one through your form: Clerk's
   verification code would never arrive and the user would never be created.

Other frameworks: `createClerkSignupHook()` takes a web `Request` and answers a `Response` (Remix, Hono, Workers,
Bun, Deno). For Express, give the raw body to `createClerkWebhookHandler()`, on a route registered before any
`express.json()`, because the signature covers the raw body:

```ts
import express from 'express';
import { createClerkWebhookHandler } from './email-validation-clerk';

const app = express();
const handle = createClerkWebhookHandler({
  apiKey: process.env.EV_API_KEY,
  signingSecret: process.env.CLERK_WEBHOOK_SIGNING_SECRET,
  clerkSecretKey: process.env.CLERK_SECRET_KEY,
});
app.post('/api/webhooks/clerk', express.raw({ type: 'application/json' }), async (req, res) => {
  const result = await handle({ body: req.body.toString('utf8'), headers: req.headers });
  res.status(result.status).json(result.body);
});
```

For a custom sign-up flow, call `checkSignupEmail()` on your server before `signUp.create()`, for example in a
Next.js server action:

```ts
'use server';
import { checkSignupEmail } from '@/lib/email-validation-clerk';

export async function checkEmail(email: string) {
  const d = await checkSignupEmail(email, { apiKey: process.env.EV_API_KEY });
  return { allow: d.allow, status: d.status, didYouMean: d.didYouMean };
}
```

In the form, stop when `allow` is `false`, and offer `didYouMean` when there is one.

To undo a wrong stop, set `email_validation` to `null` in the user's public metadata, and unban the user if you chose
`ban`.

## Choose what to stop and what happens

| Option | Default | What it does |
|---|---|---|
| `stop` | `['invalid', 'disposable']` | Statuses that stop a sign-up: any of `invalid`, `disposable`, `catch_all`, `unknown` |
| `onStop` | `flag` | `flag`, `ban`, `delete` or `none` (see below) |
| `region` | `us` | `eu` validates addresses in the EU and stores their results there ([EU data residency](https://email-validation.org/docs/eu-data-residency/)) |
| `timeoutMs` | `6000` | How long to wait for an answer before the sign-up goes through: whole milliseconds from 1 to 60000; any other value throws a `TypeError` when the handler is created |

A result marked disposable is stopped while `disposable` is in `stop`, whatever its status (the API keeps
`invalid` or `unknown` as the status of some addresses on disposable domains), except an `unknown` that means our
check ran out of time or failed (`timeout`, `internal_error`). Otherwise a `valid` result goes through, and an
`unknown` result is stopped only if you add it to `stop`, never for `timeout` or `internal_error`.

- **`flag`** writes `public_metadata.email_validation` (`{ status, reason, stopped: true, checked_at }`) on the
  user. Users cannot change public metadata. Your app reads the flag on the server, or from the session token after
  you add public metadata to it, and decides what to show.
- **`ban`** writes the same flag and bans the user. Clerk ends their sessions and refuses later sign-ins.
- **`delete`** deletes the user.
- **`none`** changes nothing and calls your `onResult` function.

Banning and deleting are off unless you choose them, because a wrongly stopped address would cost a real person
their account.

## When something fails

No key, a timeout, a network error, a rate limit, a refused key, no credits or any other error answer lets the
sign-up through. The webhook then answers `200`, so Clerk does not retry and the account stays. The handler answers
`400` to a delivery whose signature does not match or whose timestamp is more than 5
minutes off. It answers `500` only when Clerk's API failed (a server error, a rate limit or no answer). Clerk then
retries the delivery. A retry that reaches the same running server reuses the first answer; on serverless hosts it
usually reaches another one and checks again, so a long Clerk outage can cost up to 8 checks for one sign-up. If
Clerk refuses the action (a wrong secret key, for example), the handler answers `200` and the account stays, because
retrying cannot fix that.

## What it costs

Each check costs at most 1 credit, like any [validation request](https://email-validation.org/docs/api/validate/). `unknown` results, errors,
malformed addresses and test addresses are free. Using both parts checks a sign-up twice. Credits come in one-time [packs](https://email-validation.org/pricing/), from
$0.15 per 1,000 with the 50,000,000-credit pack (smaller packs cost more per credit), and new
accounts get 500 free credits (100 when you sign up with a free email provider such as Gmail, Outlook or Yahoo, another personal mailbox such as a paid one like Fastmail or one from your internet provider, or an address from a relay or alias service). Anyone can call a server-side check in a custom flow, so rate-limit it like
the rest of your sign-up and give the key a daily credit cap.

## Privacy

The file sends only the new user's address, in the body of a `POST` to `https://api.email-validation.org` (or `https://api-eu.email-validation.org`). It never puts
the address in a URL and sends it to no other host. Your API key goes only to the API, and Clerk's secret key only
to Clerk's API. The file never logs an address, and what it passes to `onResult` holds the user id, not the
address.

## Related

- [Sign-up form validation](https://email-validation.org/docs/guides/signup-form-validation/)
- [Statuses and reasons](https://email-validation.org/docs/statuses/)
- [Test addresses](https://email-validation.org/docs/test-addresses/)

## More on Clerk

- [Clerk integration](https://email-validation.org/integrations/clerk/)
