Skip to content

// auth and identity

Via API

Auth.js email verification with pingutil

With an Auth.js email provider, every address typed into the sign-in form gets a magic link, so typos bounce and temp-mail users walk in. The signIn callback runs before the link is sent, flagged with email.verificationRequest; verify the address with pingutil there and return false or a redirect for addresses you refuse.

Where it connects: Auth.js signIn callback (email.verificationRequest for magic links)

What goes wrong without it

  • Our Auth.js magic-link sign-in bounces for every mistyped address and our email provider keeps warning us about it.
  • Anyone with a temp inbox can create an account, since the magic link is the only check.
  • We tried a static blocklist in the signIn callback and it missed half the throwaway domains.

What you can do with Auth.js and pingutil

  • Verify before the magic link goes out

    On the first signIn call (email.verificationRequest is true), run /v1/verify. For status invalid, return a redirect and Auth.js never sends the email.

  • Send typos back with a suggestion

    When did_you_mean is set, redirect to your sign-in page with the suggestion in the query string so the user can correct it in one click.

  • Screen OAuth sign-ins too

    For OAuth providers the same callback receives the profile email. A fast lookup with skip_enrichment catches the rare disposable address on a social account.

Set it up

  1. 1

    Create a pingutil API key and add PINGUTIL_KEY to your environment.

  2. 2

    Open your Auth.js config (auth.ts) where the email provider is set up.

  3. 3

    Add the signIn callback below.

  4. 4

    Read the error and suggest query parameters on your sign-in page and show a message.

  5. 5

    Request a magic link for a mistyped Gmail address and confirm no email is sent.

auth.ts (Auth.js v5, Resend email provider)
import NextAuth from 'next-auth';
import Resend from 'next-auth/providers/resend';
import { PrismaAdapter } from '@auth/prisma-adapter';
import { prisma } from '@/lib/prisma';

async function verify(email: string) {
  try {
    const res = await fetch('https://pingutil.com/v1/verify', {
      method: 'POST',
      headers: {
        authorization: 'Bearer ' + process.env.PINGUTIL_KEY,
        'content-type': 'application/json',
      },
      body: JSON.stringify({ email }),
      signal: AbortSignal.timeout(5000),
    });
    return res.ok ? await res.json() : null;
  } catch {
    return null; // fail open
  }
}

export const { handlers, auth, signIn, signOut } = NextAuth({
  adapter: PrismaAdapter(prisma),
  providers: [Resend({ from: 'login@yourapp.com' })],
  callbacks: {
    async signIn({ user, email }) {
      // First call: the user asked for a magic link and nothing is sent yet.
      if (!email?.verificationRequest || !user.email) return true;

      const result = await verify(user.email);
      if (!result) return true;

      if (result.did_you_mean) {
        return '/login?error=typo&suggest=' + encodeURIComponent(result.did_you_mean);
      }
      if (result.status === 'invalid') return '/login?error=undeliverable';
      return true;
    },
  },
});

What to do with each result

pingutil resultAction in Auth.js
did_you_mean is setRedirect to /login with the suggestion; no link is sent
status: "invalid"Redirect to /login?error=undeliverable; no link is sent
status: "risky"Return true; optionally flag the user in your database after sign-in
status: "valid" or "unknown"Return true
Timeout, 429 or 5xxReturn true (fail open)

Limits to plan for

  • The signIn callback runs on every sign-in request, including returning users. Definitive results are cached 30 days, but each call counts toward 300 verified addresses a day (3,000 a month) per account; skip the check for emails already in your users table. Those are Free plan limits; Enterprise has custom limits.
  • A first-seen address on a slow mail server can take several seconds, and the user waits for the "check your email" page. Swap to /v1/lookup with skip_enrichment if that delay matters more than catching typos.
  • Catch-all domains return risky. The snippet lets them through, since the magic link itself will show whether the mailbox works.

Auth.js documentation

Auth.js is a trademark of its owner. This integration uses Auth.js's documented extension points; it is not an official Auth.js app.

Common questions

Why check only when verificationRequest is true?
Per the Auth.js reference, the first call carries verificationRequest: true before the email is sent, and the second call, after the link is clicked, does not. Checking on the first call is what stops the email going out.
Does this work with NextAuth v4?
Yes. The signIn callback receives the same user and email arguments in v4; only the provider imports and config export differ.

Stop bad addresses in Auth.js today

Sign in with your email, create an API key and paste it into the step above. Test on a few real addresses first: the live demo shows exactly what your Auth.js setup will receive.