Disposable Email Domain Blocklist

Next.js integration · server route

Next.js disposable email validation

Put the check in a route handler or server action so a caller cannot bypass it by skipping your browser UI.

Answer: validate the email at app/api/signup/route.ts before calling your Auth provider. Return a stable public code and keep provider stack details out of the response.

Route handler

import { NextResponse } from 'next/server'
import { isDisposableEmail } from '@internal/disposable-email-core'

export async function POST(request: Request) {
  const body = (await request.json()) as { email?: unknown }
  const email = typeof body.email === 'string' ? body.email : ''

  if (isDisposableEmail(email)) {
    return NextResponse.json(
      { code: 'SIGNUP_EMAIL_NOT_ALLOWED' },
      { status: 400 }
    )
  }

  return NextResponse.json({ accepted: true })
}

Implementation checklist

  1. Keep the matcher on the server; the browser check is only UX.
  2. Handle invalid_input separately from a disposable match.
  3. Keep an allowlist for reviewed exceptions.
  4. Retain rate limits, CAPTCHA, email verification, and provider abuse controls.
  5. Test both user@vtmpj.com and user@gmail.com.

See the JSON contract →Source guide