In this tutorial we'll test Firebase Authentication emails both against the Auth emulator and against a real Firebase staging project. The Auth emulator doesn't send emails, but you can access all the links Firebase would have sent at a REST endpoint. Firebase does send emails in the staging scenario, so we'll use testmail.app to receive them and extract the action link for the test to open.
The emulator is free and fast, so you can afford to run these tests on every code change (push). The real-email run checks the email your users get, the link inside it and your authorized domains settings, since without proper configuration links won't work. On the free (Spark) Firebase plan, keep in mind that you can only send 5 email link sign-in emails per day.
This guide gives you:
- A table of Firebase's three auth emails: how each is sent, finished and limited
- One link helper that reads from the emulator or from a real inbox, so every test runs both ways
- Tests for email link sign-in (same device, another device, the wrong address, a used link), email verification and password reset
- What changes against a real project, and how to split the two runs in CI
We ran every test here against the Firebase Auth emulator (firebase-tools 15.34.2) with the Firebase JS SDK 13.2.0 and Playwright 1.63 on Node.js 22. The real-project parts follow Firebase's documentation, and we point out where the emulator and a real project behave differently.
Firebase's three auth emails at a glance
Firebase sends these emails itself (from its own templates). What you can test is how your app starts and finishes these flows, and that the email (with a working link) arrived:
| Email link sign-in | Email verification | Password reset | |
|---|---|---|---|
| Sent by | sendSignInLinkToEmail(auth, email, { url, handleCodeInApp: true }) | sendEmailVerification(user, { url }) | sendPasswordResetEmail(auth, email) |
requestType in the emulator | EMAIL_SIGNIN | VERIFY_EMAIL | PASSWORD_RESET |
mode in the link | signIn | verifyEmail | resetPassword |
| Finished by | Always your app, with signInWithEmailLink(auth, email, url) | Firebase's hosted page, or your own handler with applyActionCode | Firebase's hosted page, or your own handler with confirmPasswordReset |
| Needs the address again | Yes: your app passes it in, from localStorage or by asking the user | No | No |
| Opened a second time | auth/invalid-action-code | auth/invalid-action-code | auth/invalid-action-code |
| Spark plan limit | 5 emails a day | 1,000 emails a day | 150 emails a day |
| Blaze plan limit | 25,000 emails a day | 100,000 emails a day | 10,000 emails a day |
If you're on the free (Spark) Firebase plan, keep in mind that you can only send 5 email link sign-in emails per day. This won't even allow you to run the tests we're going to write in this tutorial twice (there are four of them), so we recommend using a project on the Blaze plan (with billing enabled) for testing in a real environment (we'll call it staging). Firebase's limits page says this limit was recently changed and that exceeding it requires a billing account. Run email link sign-in against the emulator as often as you like.
Set up: the emulator, an inbox and one link helper

We're going to write a function called nextLink() that'll work in both scenarios: when FIREBASE_AUTH_EMULATOR_HOST is set it'll get the link from the emulator, otherwise it'll wait for the email to arrive in the testmail.app inbox and extract the link from it. Three pieces make that work.
1. Run the tests inside the Auth emulator
Add the emulator to firebase.json. We've disabled the emulator UI since we don't need it for our tests:
{
"emulators": {
"auth": { "port": 9099 },
"ui": { "enabled": false },
"singleProjectMode": true
}
}We're going to run our tests with firebase emulators:exec. This command first starts the emulator, then runs the command we pass to it (in our case the tests), and when they're done shuts the emulator down. It'll set FIREBASE_AUTH_EMULATOR_HOST=127.0.0.1:9099 for the command it runs, so the link helper knows it's an emulator run. To make sure we're not accidentally running against production we're going to use a project ID prefixed with demo- (it won't point to a real Firebase project):
npx firebase emulators:exec --only auth --project demo-test "npx playwright test"In order for our app to work with the emulator, we need to call connectAuthEmulator before we use auth for the first time. We've left it up to you how you'll pass the configuration to your app; in our case we're setting the emulator URL on the page itself (only in test builds):
import { initializeApp } from 'firebase/app';
import { getAuth, connectAuthEmulator } from 'firebase/auth';
const auth = getAuth(initializeApp(firebaseConfig));
if (window.AUTH_EMULATOR_URL) connectAuthEmulator(auth, window.AUTH_EMULATOR_URL, { disableWarnings: true }); // http://127.0.0.1:9099 in test builds2. Add an inbox helper
Each Inbox is a unique testmail.app email address under your namespace. Each tag is equivalent to a new Inbox, so if we use a unique tag for each test we won't have to explicitly create an Inbox (email address). next() holds a live query open until an email arrives and remembers the last one it returned. When we're running against the emulator we don't actually need TESTMAIL_APIKEY since no emails will be sent, but we do need TESTMAIL_NAMESPACE in order to use the same email addresses in both scenarios.
// tests/inbox.ts: a new testmail.app inbox for each test
import { randomBytes } from 'node:crypto';
const API = 'https://api.testmail.app/api/json';
const { TESTMAIL_APIKEY = '', TESTMAIL_NAMESPACE = '' } = process.env;
const RUN_TAG = process.env.RUN_TAG ?? `local-${Date.now().toString(36)}`;
export type Email = { subject: string; from: string; html: string; text: string; timestamp: number };
export class Inbox {
readonly tag = `${RUN_TAG}.${randomBytes(4).toString('hex')}`;
readonly address = `${TESTMAIL_NAMESPACE}.${this.tag}@inbox.testmail.app`;
private since = 0;
/** Waits on testmail.app's side (live query) for the next email to this address. */
async next(timeoutMs = 90_000): Promise<Email> {
const params = new URLSearchParams({ apikey: TESTMAIL_APIKEY, namespace: TESTMAIL_NAMESPACE, tag: this.tag, livequery: 'true' });
if (this.since) params.set('timestamp_from', String(this.since));
const res = await fetch(`${API}?${params}`, { signal: AbortSignal.timeout(timeoutMs) }).catch((error) => {
throw error.name === 'TimeoutError' ? new Error(`No email to ${this.address} within ${timeoutMs / 1000} s`) : error;
});
const body = await res.json();
if (body.result !== 'success') throw new Error(`testmail.app: ${body.message}`);
const email: Email = body.emails.at(-1); // newest first, so the last one is the oldest new email
this.since = email.timestamp + 1;
return email;
}
}
export const links = (email: Email) => [...email.html.matchAll(/href="([^"]+)"/g)].map((m) => m[1].replaceAll('&', '&'));
export const codeFrom = (email: Email) => email.text.match(/\b\d{6}\b/)?.[0] ?? '';3. Add one link helper for both runs
When running against the emulator we can access all the links Firebase would have sent via the oobCodes REST endpoint. When running against a real Firebase project we'll have to parse the link from the email testmail.app receives. nextLink works in both scenarios. Firebase action links always include a parameter named oobCode, so actionLink looks for that in the HTML or plain text, with either kind of quotes.
// tests/firebase-links.ts: the next Firebase action link for an address, from the Auth emulator or from the real email
import type { Inbox, Email } from './inbox';
type RequestType = 'EMAIL_SIGNIN' | 'VERIFY_EMAIL' | 'PASSWORD_RESET';
const EMULATOR = process.env.FIREBASE_AUTH_EMULATOR_HOST; // set by `firebase emulators:exec`, for example 127.0.0.1:9099
const PROJECT = process.env.FIREBASE_PROJECT_ID ?? 'demo-test';
const seen = new Set<string>();
const MODES: Record<RequestType, string> = { EMAIL_SIGNIN: 'signIn', VERIFY_EMAIL: 'verifyEmail', PASSWORD_RESET: 'resetPassword' };
/** Every Firebase action link carries an oobCode, whether it points at firebaseapp.com or at your own handler. */
export const actionLink = (email: Email) =>
[...`${email.html} ${email.text}`.matchAll(/https?:\/\/[^\s"'<>]+/g)]
.map((m) => m[0].replaceAll('&', '&'))
.find((url) => url.includes('oobCode='));
/** Waits for the next link of this type: from the emulator when it's running, otherwise from the inbox. */
export async function nextLink(inbox: Inbox, requestType: RequestType, timeoutMs = 90_000): Promise<string> {
if (!EMULATOR) {
// Skip other Firebase emails to this address, such as the verification email sent at sign-up
for (;;) {
const link = actionLink(await inbox.next(timeoutMs));
if (link && new URL(link).searchParams.get('mode') === MODES[requestType]) return link;
}
}
// The emulator sends no email. It keeps every link it would have sent at this endpoint instead.
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
const res = await fetch(`http://${EMULATOR}/emulator/v1/projects/${PROJECT}/oobCodes`);
const { oobCodes } = await res.json();
const oob = oobCodes.find((o) => o.email === inbox.address.toLowerCase() && o.requestType === requestType && !seen.has(o.oobCode));
if (oob) { seen.add(oob.oobCode); return oob.oobLink; }
await new Promise((resolve) => setTimeout(resolve, 250));
}
throw new Error(`No ${requestType} link for ${inbox.address} in the Auth emulator`);
}
/** The same action on your own handler page, whichever host the link points at. */
export function handlerPath(link: string) {
if (!EMULATOR) return link; // a real email already links to your handler: test that link as it is
const { searchParams } = new URL(link);
return `/auth/action?mode=${searchParams.get('mode')}&oobCode=${searchParams.get('oobCode')}`;
}We've set a rather large timeout in the Playwright config: longer than the 90 seconds we wait for emails to arrive:
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests',
timeout: 120_000, // longer than the 90-second email wait
retries: process.env.CI ? 1 : 0,
use: { baseURL: process.env.BASE_URL ?? 'http://localhost:3000', trace: 'on-first-retry' },
// emulator runs start a test build of the app; real-email runs test BASE_URL
webServer: process.env.FIREBASE_AUTH_EMULATOR_HOST ? { command: 'npm run start:test', url: 'http://localhost:3000' } : undefined,
});Test email link sign-in
The app under test follows Firebase's own sample: it sends the link with handleCodeInApp: true, keeps the address in localStorage, and on the landing page asks for the address with window.prompt when this browser didn't request the link. These are the relevant lines from our test app:
// Ask for a sign-in link
await sendSignInLinkToEmail(auth, email, { url: `${location.origin}/finish`, handleCodeInApp: true });
localStorage.setItem('emailForSignIn', email); // so the same browser doesn't have to ask again
// On /finish, the continue URL
if (isSignInWithEmailLink(auth, location.href)) {
let email = localStorage.getItem('emailForSignIn');
if (!email) email = window.prompt('Please provide your email for confirmation'); // another device
const { user } = await signInWithEmailLink(auth, email, location.href);
localStorage.removeItem('emailForSignIn');
}The link the test opens differs between the two runs, and the test doesn't care. From the emulator it's an http://127.0.0.1:9099/emulator/action?mode=signIn&… link; from a real email it goes to Firebase's action handler (on PROJECT_ID.firebaseapp.com unless you set your own). Both send the browser on to your continue URL with the code, where isSignInWithEmailLink picks it up.
// tests/firebase.spec.ts: Firebase email link sign-in, email verification and password reset
import { test, expect, type Page } from '@playwright/test';
import { Inbox } from './inbox';
import { nextLink, handlerPath } from './firebase-links';
async function requestLink(page: Page, address: string) {
await page.goto('/');
await page.getByLabel('Email').fill(address);
await page.getByRole('button', { name: 'Email me a sign-in link' }).click();
await expect(page.getByRole('status')).toHaveText('Check your email');
}
test('signs in with the email link', async ({ page }) => {
const inbox = new Inbox();
await requestLink(page, inbox.address);
await page.goto(await nextLink(inbox, 'EMAIL_SIGNIN'));
await expect(page.getByRole('heading')).toHaveText(`Signed in as ${inbox.address}`);
});
test('on another device, it asks for the address again', async ({ page, browser }) => {
const inbox = new Inbox();
await requestLink(page, inbox.address);
const link = await nextLink(inbox, 'EMAIL_SIGNIN');
const other = await browser.newContext(); // a browser with no emailForSignIn in localStorage
const phone = await other.newPage();
let asked = '';
phone.once('dialog', (dialog) => { asked = dialog.message(); dialog.accept(inbox.address); });
await phone.goto(link);
await expect(phone.getByRole('heading')).toHaveText(`Signed in as ${inbox.address}`);
expect(asked).toBe('Please provide your email for confirmation');
await other.close();
});
test('a different address is refused', async ({ page, browser }) => {
const inbox = new Inbox();
await requestLink(page, inbox.address);
const link = await nextLink(inbox, 'EMAIL_SIGNIN');
const other = await browser.newContext();
const phone = await other.newPage();
phone.once('dialog', (dialog) => dialog.accept('[email protected]'));
await phone.goto(link);
await expect(phone.getByRole('status')).toHaveText('auth/invalid-email');
await other.close();
});
test('a used link stops working', async ({ page, browser }) => {
const inbox = new Inbox();
await requestLink(page, inbox.address);
const link = await nextLink(inbox, 'EMAIL_SIGNIN');
await page.goto(link);
await expect(page.getByRole('heading')).toHaveText(`Signed in as ${inbox.address}`);
const other = await browser.newContext(); // someone who finds the link later
const second = await other.newPage();
second.once('dialog', (dialog) => dialog.accept(inbox.address));
await second.goto(link);
await expect(second.getByRole('status')).toHaveText('auth/invalid-action-code');
await other.close();
});What each one proves:
- Signs in with the email link. The whole flow on one device: the request, the link, the landing page and the session. Our app shows
Signed in as …; assert on whatever your signed-in page shows. - Another device. A new browser context has no
emailForSignIn, which is what happens when someone asks on a laptop and opens the email on a phone. Playwright answers thewindow.promptthrough thedialogevent. If your app asks with a form instead, fill the form. - A different address. Firebase verifies that the email address the app provides matches the one the link was sent to (otherwise
auth/invalid-email). This is Firebase’s safeguard against someone using a passwordless sign-in link on the wrong device or account, as described in their docs. - A used link. If the app opens the same link twice, the second time it will receive
auth/invalid-action-codesince action codes can only be used once. (This error code can also be returned for malformed action codes and Firebase notes that it may be returned for expired action codes.)

If the app re-uses the email address from the continue URL, that should be changed. Firebase warns against passing the user's address in the continue URL and re-using it from there because it may allow session injection attacks.
Test email verification and password reset
Firebase provides hosted confirmation pages for email verification and password reset by default. Firebase also allows you to specify your own action URL to handle these actions. Go to Security, Authentication in the Firebase console, click the Templates tab, then select "customize action URL" and update the link. Firebase will use this link in all of the project’s templated emails. The page should call either applyActionCode or confirmPasswordReset, depending on the action, and send sign-in links (mode=signIn) on to the page that finishes sign-in. For brevity, here are only the relevant lines from our confirmation page:
// /auth/action: the page your custom action URL points at
const params = new URLSearchParams(location.search);
const code = params.get('oobCode');
if (params.get('mode') === 'signIn') {
location.replace(`/finish${location.search}`); // a custom action URL gets sign-in links too
}
if (params.get('mode') === 'verifyEmail') {
await applyActionCode(auth, code); // then show "Email verified"
}
if (params.get('mode') === 'resetPassword') {
const email = await verifyPasswordResetCode(auth, code); // shows whose password this is
// ...and when the form is submitted:
await confirmPasswordReset(auth, code, newPassword);
}With a custom confirmation page, the Playwright tests will navigate to your page and perform any actions needed to confirm the action (like entering a new password for password reset). In the following tests, handlerPath() turns the emulator’s link into a link to your /auth/action page with the same oobCode and mode; a real email already links to your page, so it’s opened as it is. This allows us to test against our own handler page using either kind of link.
// tests/firebase.spec.ts, continued
async function signUp(page: Page, address: string, password: string) {
await page.goto('/signup');
await page.getByLabel('Email').fill(address);
await page.getByLabel('Password').fill(password);
await page.getByRole('button', { name: 'Create account' }).click();
await expect(page.getByRole('status')).toHaveText('Check your email to verify your address');
}
test('verifies the email address', async ({ page }) => {
const inbox = new Inbox();
await signUp(page, inbox.address, 'first-password-123');
await page.goto('/account');
await expect(page.locator('#verified')).toHaveText('no');
const verifyPage = handlerPath(await nextLink(inbox, 'VERIFY_EMAIL'));
await page.goto(verifyPage);
await expect(page.getByRole('heading')).toHaveText('Email verified');
await page.goto('/account');
await page.getByRole('button', { name: 'Refresh' }).click();
await expect(page.locator('#verified')).toHaveText('yes');
await page.goto(verifyPage); // the same link, a second time
await expect(page.getByRole('status')).toHaveText('auth/invalid-action-code');
});
test('resets the password', async ({ page }) => {
const inbox = new Inbox();
await signUp(page, inbox.address, 'first-password-123');
await page.goto('/reset');
await page.getByLabel('Email').fill(inbox.address);
await page.getByRole('button', { name: 'Email me a reset link' }).click();
await expect(page.getByRole('status')).toHaveText('Check your email');
const resetPage = handlerPath(await nextLink(inbox, 'PASSWORD_RESET'));
await page.goto(resetPage);
await expect(page.getByRole('heading')).toHaveText(`New password for ${inbox.address}`);
await page.getByLabel('New password').fill('second-password-456');
await page.getByRole('button', { name: 'Save password' }).click();
await expect(page.getByRole('status')).toHaveText('Password changed');
await page.goto('/signin-password');
await page.getByLabel('Email').fill(inbox.address);
await page.getByLabel('Password').fill('second-password-456');
await page.getByRole('button', { name: 'Sign in' }).click();
await expect(page.getByRole('heading')).toHaveText(`Signed in as ${inbox.address}`);
await page.goto(resetPage); // the same reset link, a second time
await expect(page.getByRole('status')).toHaveText('auth/invalid-action-code');
});There are a couple things to note about these tests:
emailVerifieddoesn't update by itself. The value will not be updated unlessuser.reload()is called, so in this example we’ve added a Refresh button which the test clicks. Otherwise, the test would incorrectly fail even though the user was verified.- Each link works once. Similar to passwordless sign-in, the second visit to both the email verification link and the password reset link fails with
auth/invalid-action-codesince each link can only be used once.
If you keep Firebase's hosted pages
Without a custom action URL, your E2E tests will open the link itself (page.goto(link)) and wait for a confirmation message on Firebase's page before moving on, because that page applies the code from its own script. For password resets, Firebase’s page includes a form to submit a new password. The emulator can't stand in for this: its action endpoint verifies an address as soon as the link is opened, and for a reset it expects the new password as a newPassword query parameter instead of showing a form. So for hosted pages, the emulator run tests your app's side and the real-email run tests the page.
Run the same tests against a real project
While tests against the emulator ensure your app’s behavior is correct, testing against a real Firebase project ensures that your users will receive emails with working links on your domain from the sender you specified. To point these tests at a staging Firebase project:
- Use a staging Firebase project. If you frequently run the passwordless sign-in tests, you will need to be on the Blaze pricing plan because Firebase limits projects on the Spark plan to 5 email link sign-in emails per day.
- Make sure that you’ve enabled Email/Password sign-in (and Email link sign-in, if testing passwordless sign-in) for your Firebase project.
- Authorize your app’s domain (Security, Authentication, the Settings tab, Authorized domains). Projects created after April 28, 2025 won’t have
localhostadded by default. If you try to use a continue URL whose domain isn’t listed, you’ll get anauth/unauthorized-continue-urierror. - Build your app without
connectAuthEmulatorand run Playwright outsideemulators:exec. This makes sure thatFIREBASE_AUTH_EMULATOR_HOSTisn’t set andnextLinkwill get the link from the real email in the testmail.app inbox instead of the emulator:
TESTMAIL_APIKEY=your-api-key TESTMAIL_NAMESPACE=your-namespace BASE_URL=https://staging.example.com \
npx playwright testTwo gotchas to keep in mind: the email subject and body will include a timestamp if you’re using Firebase’s default email link sign-in email template (Firebase does this so that email clients don’t collapse multiple emails into a single thread which hides the action link). If your test asserts on the subject line, make sure you take this into account and don’t expect an exact match. Firebase lets you configure the sender name, sender address, reply-to address and subject line for each type of email (and the email content too for password reset emails). You can also use your own sending domain if you verify it with Firebase. These are good things to test since only the real-email run can check them.
Split the runs in CI
We recommend running the emulator tests on all PRs and the real-email tests less frequently, on pushes to main against staging. No secrets are needed for the emulator tests and no emails are sent. The real-email tests do require secrets and will send emails. Make sure you use Playwright’s webServer option to spin up a test build of your app for the emulator CI job:
# .github/workflows/auth-emails.yml
name: Auth emails
on:
pull_request:
push:
branches: [main]
env:
RUN_TAG: gh-${{ github.run_id }}-${{ github.run_attempt }}
TESTMAIL_NAMESPACE: ${{ vars.TESTMAIL_NAMESPACE }}
jobs:
emulator:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: lts/*
cache: npm
- run: npm ci
- run: npx playwright install --with-deps chromium
- run: npx firebase emulators:exec --only auth --project demo-test "npx playwright test"
real-email:
if: github.event_name == 'push'
runs-on: ubuntu-latest
environment: staging
env:
BASE_URL: ${{ vars.STAGING_URL }}
TESTMAIL_APIKEY: ${{ secrets.TESTMAIL_APIKEY }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: lts/*
cache: npm
- run: npm ci
- run: npx playwright install --with-deps chromium
- run: npx playwright testOur CI/CD email testing guide goes deeper on some of these topics (dealing with secrets and forked PRs, parallel jobs, persisting emails on failure, etc.).
Sign in once for every other test
Most of the other tests in your suite likely don’t care about actually testing email link sign-in but will still require a signed in user. Instead of going through the whole flow for each of those tests, use Firebase’s Admin SDK to generate a sign-in link without sending an email (generateSignInWithEmailLink has a separate and much higher daily limit). Then use that link in a Playwright setup project to sign in and save the browser state. There’s just one gotcha. Firebase Authentication saves its session in IndexedDB so you’ll need to make sure you’re passing indexedDB: true to storageState or your state will be restored as logged out (Firebase Authentication is actually the example use case in Playwright’s docs for this option!). We tested this both ways: without the option, the saved state loads as signed out.
// tests/auth.setup.ts: sign in once without sending an email, then save the session (IndexedDB included)
import { test as setup, expect } from '@playwright/test';
import { initializeApp } from 'firebase-admin/app';
import { getAuth } from 'firebase-admin/auth';
initializeApp({ projectId: process.env.FIREBASE_PROJECT_ID ?? 'demo-test' }); // a real project also needs credentials
setup('sign in', async ({ page, baseURL }) => {
const email = `${process.env.TESTMAIL_NAMESPACE}.setup-${Date.now()}@inbox.testmail.app`;
const link = await getAuth().generateSignInWithEmailLink(email, { url: `${baseURL}/finish`, handleCodeInApp: true });
page.once('dialog', (dialog) => dialog.accept(email)); // this browser didn't ask for the link
await page.goto(link);
await expect(page.getByRole('heading')).toHaveText(`Signed in as ${email}`);
await page.context().storageState({ path: 'playwright/.auth/user.json', indexedDB: true }); // Firebase keeps the session in IndexedDB
});Add a setup project to your Playwright config with testMatch: /.*\.setup\.ts/ and make your other project depend on it. Then add test.use({ storageState: 'playwright/.auth/user.json' }) to your tests. When running against the emulator, you don’t need to provide credentials to the Admin SDK (since it’ll use FIREBASE_AUTH_EMULATOR_HOST). For actual Firebase projects, set FIREBASE_PROJECT_ID and provide a service account via GOOGLE_APPLICATION_CREDENTIALS or similar. Make sure you add playwright/.auth to your .gitignore since it’ll contain a valid auth session!
Troubleshooting
| What you see | Why | Fix |
|---|---|---|
auth/unauthorized-continue-uri when sending a link | The continue URL's domain isn't an authorized domain. Projects created after April 28, 2025 don't list localhost by default | Add the domain under Security, Authentication, Settings, Authorized domains |
| Email link sign-in works a few times, then stops for the day | The Spark plan allows 5 email link sign-in emails a day | Run sign-in tests against the emulator, use Blaze for the staging project, and sign in other tests with Admin SDK links |
auth/emulator-config-failed | connectAuthEmulator ran after auth had already made a request | Call it right after getAuth(), before anything else uses auth |
nextLink times out in an emulator run | The app is talking to a real project instead of the emulator, or FIREBASE_PROJECT_ID doesn't match --project | Check that the test build calls connectAuthEmulator, and use the same project ID in both places |
auth/invalid-action-code on the first visit | The link was already opened (by an earlier step, or by an email scanner), or it came from an emulator that has since restarted; its codes live in memory | Open each link once, and request a new one after restarting the emulator |
auth/invalid-email when finishing on another device | The address typed in doesn't match the one the link was sent to | Use the same address. The check is deliberate, so don't work around it |
emailVerified is still false after the link worked | The signed-in user object keeps its old value | await user.reload() before reading it |
Tests that load storageState start signed out | Firebase keeps the session in IndexedDB, which storageState leaves out by default | storageState({ path, indexedDB: true }) |
| The emulator logs "canHandleCodeInApp is unsupported in Auth Emulator" | The emulator sends every link through its own web endpoint | Nothing: links still land on your continue URL |
| The emulator's reset link answers "missing newPassword query parameter" | Its own reset endpoint takes the new password in the URL instead of showing a form | Open your handler page with handlerPath(), as in the reset test |
FAQ
Does the Firebase Auth emulator send real emails?
No. It outputs each link to the console and also stores it where it can be retrieved via GET /emulator/v1/projects/{project-id}/oobCodes (includes the email address, action code, action link, and request type). This is useful for testing your app’s behavior for all of these flows but doesn’t test the actual emails that your users receive.
Do I still need a real inbox if I use the emulator?
For testing the emails themselves, yes. You can test that the sender, subject line and email template look correct, that your custom domain or action URL appears in the link, and that the link works on your authorized domain. We still recommend running these against a staging project less frequently than the emulator tests, which can run on every push.
How long are Firebase email links valid?
We couldn’t find any Firebase docs that mention expiration for these links (and the emulator doesn’t expire links). An expiry test will need to run with a real Firebase project. Plan for links to stop working. Make sure your app handles auth/expired-action-code and auth/invalid-action-code the same way, by allowing the user to get another email.
Why does Firebase ask for the email again?
Firebase requires signInWithEmailLink to receive the address the link was sent to as a security measure, so that the link can’t sign in the wrong person or the wrong device. Firebase’s own example app stores the email in localStorage so that it only prompts the user if they use a different browser. This is why our sign in on another device test responds to a dialog.
Can I test password reset without Firebase's hosted page?
Yes! Configure a custom action URL and make sure it goes to your custom page (like we do in the password reset test above). If you are using Firebase’s page, visit the link, fill out Firebase’s password reset form and wait for Firebase’s success message. This part will only work with a real Firebase project.
Can these tests run in parallel?
Yes! Since we’re generating a new email address for each test and nextLink accounts for the email address and type of email, there shouldn’t be any issues with tests stepping on each other’s toes.
