Integration
Integrating with Next.js
Learn how to integrate nofakemails with your Next.js application
nofakemails Team
1/15/2026
Next.jsReactTypeScript
Integrating with Next.js
This guide shows you how to integrate nofakemails email validation into your Next.js application.
Installation
First, install the necessary dependencies:
npm install axios
Setting Up Environment Variables
Add your API key to .env.local:
NOFAKEMAILS_API_KEY=your_api_key_here
Creating a Validation Function
Create a new file lib/nofakemails.ts:
export async function validateEmail(email: string) { const response = await fetch( `https://api.nofakemails.com/v1/email/${encodeURIComponent(email)}`, { headers: { 'X-API-Key': process.env.NOFAKEMAILS_API_KEY!, }, } ) if (!response.ok) { throw new Error('Validation failed') } return response.json() }
Using in a Server Action
'use server' import { validateEmail } from '@/lib/nofakemails' export async function checkEmail(formData: FormData) { const email = formData.get('email') as string const result = await validateEmail(email) if (result.disposable) { return { error: 'Disposable emails are not allowed' } } return { success: true } }