This repository contains the fce-example-next-auth project, which serves as a comprehensive example repository for developers looking to test and integrate their NextAuth.js-based applications with FreeCustom.Email's SDK.
This example demonstrates how to seamlessly integrate our temporary, privacy-focused email service into a Next.js application, enabling smooth, reliable authentication flows (such as magic links, OTPs, and credential validations) in testing environments using Playwright.
- Next Auth Integration: A fully functional Next.js application utilizing
next-authfor authentication. - SDK Example: Clear, structured examples showing how to interact with the FreeCustom.Email SDK to retrieve, parse, and verify emails automatically during tests.
- Modern UI/UX: Includes a beautifully styled sign-in and authentication flow inspired by NextAuth's default minimalist and accessible design.
- Playwright Testing Ready: Easily integrate your automated end-to-end tests using this boilerplate as a starting point.
You need to set up environment variables for both the main Playwright tests and the NextAuth application.
-
Main Playwright Tests Environment (
/.env): Copy the/.env.exampleto/.env:cp .env.example .env
Required Variables:
FCE_API_KEY: Your FreeCustom.Email API key.- Get it here: API Dashboard - Keys (Requires Auth on FreeCustom.Email)
-
Next Auth App Environment (
/next-auth-example/.env): Navigate to the Next Auth app directory and copy the.env.example:cd next-auth-example cp .env.example .envRequired Variables:
AUTH_RESEND_KEY: Your Resend API key for sending emails.EMAIL_FROM: Sender email address (e.g., auth@freecustom.email).AUTH_SECRET: Secret for NextAuth.
-
Start the Next.js development server: In the
next-auth-examplefolder, run:npm run dev
The application will be available at
http://localhost:3000. -
Run Playwright tests: In the root folder of this repository, run:
npx playwright test --ui
Below is an example of our testing script from tests/auth.spec.ts.
import { test, expect } from "@playwright/test";
import { FreecustomEmailClient } from "freecustom-email";
const apiKey = process.env.FCE_API_KEY;
if (!apiKey) {
throw new Error("FCE_API_KEY environment variable is missing.");
}
const fce = new FreecustomEmailClient({
apiKey: apiKey,
});
for (let i = 0; i < 10; i++) {
test(`signup with email verification ${i}`, async ({ page }) => {
// Stagger requests to avoid rate limiting
await new Promise(r => setTimeout(r, i * 100));
const inbox = `pw-test-${Date.now() + Math.random()}@ditapi.info`;
await fce.inboxes.register(inbox, true);
await fce.inboxes.startTest(inbox, "e2e-signup-1");
await page.goto("http://localhost:3000/auth/signin");
await page.fill('[name="email"]', inbox);
await page.fill('[name="password"]', "Str0ng!Pass#99");
await page.click('[type="submit"]');
// NOTE: waitForOtp functionality requires a paid plan!
const otp = await fce.otp.waitFor(inbox, { timeoutMs: 30_000 });
await page.fill('[name="otp"]', otp);
await page.click('[data-testid="verify-btn"]');
await expect(page).toHaveURL("http://localhost:3000/dashboard");
// YOU CAN CUSTOMIZE THIS BEHAVIOR:
// It's a good practice to unregister the used inbox at the end of the test.
// await fce.inboxes.unregister(inbox);
// Alternatively, using the client: await fce.inboxes.unregister(inbox);
});
}Important Notes for Testing:
- Debugging: If you are having issues receiving emails or tracking requests, visit the Debugging Events Dashboard (Requires Auth on FreeCustom.Email).
- Paid Feature: The
waitForOtpfunction shown in the example requires a paid plan to work. Check pricing here: FreeCustom.Email Pricing.
- Contact Page: https://www.freecustom.email/contact
- Support Email: dishant@dishs.tech
This project is licensed under the Apache License 2.0. See the LICENSE file for details.