# Stop Bad Emails at Auth.js Sign-up

URL: https://email-validation.org/docs/guides/authjs/
Updated: 2026-11-25

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

Keep sign-ups with bad email addresses out of an app that uses Auth.js (NextAuth.js v5). A small file you add to
your Auth.js configuration checks each new user's address with the API. When the result is a status you chose to
stop (by default `invalid` and `disposable`), Auth.js refuses the sign-up. If the API is slow or down, the sign-up
goes through.

It is one TypeScript file with no dependencies, under the MIT licence (the text is at the top of the file).
Download it: [email-validation-authjs.ts](https://email-validation.org/downloads/authjs/email-validation-authjs.ts). It runs on the server side
of your app, next to your Auth.js configuration, and never in a browser.

## How it works, and its limits

Auth.js lets an app refuse a sign-in in one place: the `signIn` callback. The file gives you one to use there. With
your adapter or an `isNewUser` function it checks only new users, so a returning user is never locked out; without
them, `checkEverySignIn: true` (below) checks every sign-in. (A signed-in user who links another provider with a
different address is checked; give your own `isNewUser` to leave that out.)

- **Social sign-in (OAuth, OIDC):** checked after the provider answers, before Auth.js creates the user. A stopped
  address gets Auth.js's "Access denied" page and no account. A provider that shares no address is let through.
- **Magic links:** checked before the mail is sent. A stopped address gets no mail and no account. When the link is
  opened, the address is not checked again.
- **Passkeys (WebAuthn, experimental in Auth.js):** checked before a new passkey account is created. A stopped
  passkey sign-up always gets Auth.js's error page.
- **Email and password (Credentials):** Auth.js has no sign-up for these: your own code creates the users. Call
  the file's `checkSignupEmail()` there, before you create the user.

To tell new users from returning ones, the file asks your Auth.js database adapter whether the person already has an
account. Without an adapter (sessions in a JWT only), Auth.js keeps no users and cannot tell. Then you choose: give
your own `isNewUser` function, or set `checkEverySignIn: true` and check every sign-in, returning users too.

## Set it up

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 a
   `NEXT_PUBLIC_` variable or browser code.
2. Copy `email-validation-authjs.ts` into your app, for example to `lib/`.
3. Add it to `auth.ts`:

   ```ts
   import NextAuth from 'next-auth';
   import { createSignInCheck } from '@/lib/email-validation-authjs';

   const adapter = PrismaAdapter(prisma); // the adapter you already use

   const checkEmail = createSignInCheck({ apiKey: process.env.EV_API_KEY, adapter });

   export const { handlers, auth, signIn, signOut } = NextAuth({
     adapter,
     providers: [/* … */],
     callbacks: { signIn: checkEmail },
   });
   ```

   If you have a `signIn` callback already, call `checkEmail(params)` first and return its answer when it is not
   `true`. SvelteKit, Express and Qwik take the same configuration; only the import of `NextAuth` changes. With
   Express, `@auth/express` currently needs Express 4: it does not mount on Express 5.
4. Test it on the server: `checkSignupEmail('disposable@sandbox.email-validation.org', { apiKey })` answers
   `allow: false`. It is a [test address](https://email-validation.org/docs/test-addresses/): free, and it always answers `disposable`. Then a
   magic link asked for that address shows Auth.js's error page and sends no mail. Test addresses receive no mail, so
   ask for a magic link only for a test address the check stops.

For email and password sign-ups, check in your own registration code, before you create the user:

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

export async function register(email: string, password: string) {
  const d = await checkSignupEmail(email, { apiKey: process.env.EV_API_KEY });
  if (!d.allow) return { error: d.didYouMean ? `Did you mean ${d.didYouMean}?` : 'Please use another email address.' };
  // …create the user
}
```

Without an adapter, pass your own record of users, or check every sign-in:

```ts
createSignInCheck({ apiKey: process.env.EV_API_KEY, isNewUser: async ({ user }) => !(await db.userExists(user.email)) });
createSignInCheck({ apiKey: process.env.EV_API_KEY, checkEverySignIn: true });
```

## Choose what to stop

| Option | Default | What it does |
|---|---|---|
| `stop` | `['invalid', 'disposable']` | Statuses that stop a sign-up: any of `invalid`, `disposable`, `catch_all`, `unknown` |
| `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` |
| `redirectTo` | Auth.js's error page | Where a stopped sign-up goes, for example `/signup?error=email` (not for passkeys) |
| `onResult` | none | Called once per sign-in with the provider, the outcome and the result, never the address |

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`.

## 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, and so does a failing database lookup. The file waits at most 6 seconds for an answer and never
retries. It never throws into Auth.js.

## 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. With your adapter or `isNewUser`, returning users are not
checked; with `checkEverySignIn: true` instead, every sign-in is checked and costs a check. 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 start a sign-in with any address, so give
the key a daily credit cap and rate-limit your sign-in route.

## 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. The file never logs an
address, and what it passes to `onResult` holds the provider and the result, not the address. A refusal reaches
Auth.js's logger only as `AccessDenied`.

## 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 Auth.js

- [Auth.js integration](https://email-validation.org/integrations/authjs/)
