# Stop Bad Emails at Firebase Sign-up

URL: https://email-validation.org/docs/guides/firebase/
Updated: 2026-11-25

> Documentation index: https://email-validation.org/llms.txt

A Firebase blocking function that checks the email address of every new sign-up and refuses the sign-ups whose
address you do not want: by default addresses that cannot receive mail (`invalid`) and throwaway inboxes
(`disposable`). It runs before Firebase Authentication creates the user. If the check cannot be made, because our API
is slow, unreachable or answers with an error, the sign-up goes through as if the function were not there.

There is nothing to install from a marketplace: you copy one file into your Firebase project's `functions/` folder.
Download it: [email-validation.cjs](https://email-validation.org/downloads/firebase/email-validation.cjs).

## What you need

- **Firebase Authentication with Identity Platform**: blocking functions are part of it. Upgrade in the Firebase
  console under **Authentication → Settings** if your project has not yet.
- Cloud Functions for Firebase, which need the **Blaze** plan, and `firebase-functions` 6 or later. 2nd gen and 1st
  gen functions both work.

## What gets checked

Every new user with an email address: sign-ups with email and password or an email link, and first sign-ins through
Google and other identity providers. Firebase does not run blocking functions for anonymous and custom-token
sign-ins, and a sign-up by phone number has no email address, so those go through unchecked.

## Set it up

1. Create an API key on the [API keys page](https://email-validation.org/app/api-keys/) with the permission **Validate addresses** and a
   [daily credit cap](https://email-validation.org/docs/authentication/#limits).
2. Copy `email-validation.cjs` into your project's `functions/` folder, beside its `package.json`.
3. Store the key as a secret: run `firebase functions:secrets:set EV_API_KEY` and paste the key when asked.
4. Export the function from `functions/index.js`:
   ```js
   exports.beforecreated = require("./email-validation.cjs").beforeUserCreated();
   ```
   On 1st gen functions, use `beforeCreate()` instead of `beforeUserCreated()`. In TypeScript, also download
   [email-validation.d.cts](https://email-validation.org/downloads/firebase/email-validation.d.cts), its types, and put it beside the `.cjs`; then in
   `src/index.ts`: `import {beforeUserCreated} from "../email-validation.cjs";` and `export const beforecreated =
   beforeUserCreated();`. In an ES module project: `import ev from "./email-validation.cjs";` and `export const
   beforecreated = ev.beforeUserCreated();`; there your `setGlobalOptions()` does not reach this function, so pass
   your options to it: `ev.beforeUserCreated({ region: "europe-west1", maxInstances: 10 })`.
5. Run `firebase deploy --only functions`. The function then shows under **Authentication → Settings → Blocking
   functions**.
6. Try it while your app does not call `sendEmailVerification` after sign-up: a test address receives no mail, so a
   verification email to it would bounce, which hurts the reputation of whoever sends it. Sign up with email and
   password using `no_mailbox@sandbox.email-validation.org`: the sign-up is refused. With `accepted@sandbox.email-validation.org`, while
   your app still does not call `sendEmailVerification`, it goes through. Do not try an email-link sign-up with a
   test address: the link is mailed before the check runs. [Test addresses](https://email-validation.org/docs/test-addresses/) return the result
   their name says, cost nothing and contact no mail server.

Already have a before-create function? Firebase Authentication holds one per project, and deploying ours beside it
fails (or, from another codebase, replaces yours). Call the check from yours instead:
`const check = await checkSignupEmail(event.data?.email);` (on 1st gen, `user.email`) and refuse when `check.stop`
is true, with `check.message`. Add `"EV_API_KEY"` to that function's `secrets`.

## Settings

Your key is a secret, so it never sits in your code. The other settings go in `functions/.env`:

| Setting | Value |
|---|---|
| `EV_REGION` | `eu` sends the checks to our EU host, for [EU data residency](https://email-validation.org/docs/eu-data-residency/). Leave it out for the US host. Both use the same keys and credits. |
| `EV_STOP_STATUSES` | The [statuses](https://email-validation.org/docs/statuses/) that refuse a sign-up, separated by commas, from `valid`, `invalid`, `catch_all`, `unknown` and `disposable`. Leave it out for `invalid,disposable`. `none` refuses nothing and only writes each result to the function's logs, a way to see what it would do first. |
| `EV_DENY_MESSAGE` | The message the person signing up gets when they are refused. Leave it out for ours (below). |

Refusing more than the default turns away more real people: a `catch_all` domain accepts mail for every address, so
the mailbox may well exist, and an `unknown` result means the mail server did not let us check. An `unknown` result
caused by our own side (reason `timeout` or `internal_error`) never refuses a sign-up, whatever you choose.

## What the person sees

The sign-up call in your app fails with Firebase's error for a refused sign-up, which carries this message:

| Status | Message |
|---|---|
| `invalid` | This email address cannot receive email. Please check it or use another address. When our API suggests a correction, it adds: Did you mean …? |
| `disposable` | Please sign up with a permanent email address, not a disposable one. |
| any other you chose | Please sign up with a different email address. |

Firebase wraps the message in its own words, so most apps show their own sentence when the error's message contains
`Cloud Function`. Your function's logs show the status, our reason and the request id for each refused sign-up.

## When the check cannot be made

Firebase gives a blocking function 7 seconds, including the time to start it, and fails the sign-up after that. The
function waits at most 4 seconds for our answer, so a slow answer does not cost a sign-up unless starting the
function took more than about 3 seconds (`minInstances: 1` in your function options reduces that: it keeps one
instance warm, though a sign-up that needs a new instance can still start cold). With no answer in time, a
network error, a wrong or missing key, no credits left, a rate limit or any other error, the sign-up goes through and
the function writes one line to its logs with the reason, never the address. A check is never retried. After a rate
limit or a busy answer (HTTP 429 or 503), the function instance sends no check for the time our API asks (30 seconds
if it names none, at most 5 minutes); sign-ups in that time are not checked.

## What it costs

Each check costs at most 1 credit, as with any [validation request](https://email-validation.org/docs/api/validate/); `unknown` results, errors and
test addresses are free. The same person trying again with the same address is checked again, and a
[repeat check](https://email-validation.org/docs/api/validate/#repeat-checks) also costs 1 credit. A check that takes more than 4 seconds can
still finish on our side and use its credit after the function has stopped waiting for it. Credits come in one-time [packs](https://email-validation.org/pricing/), as
little as $0.15 per 1,000 with the 50,000,000-credit pack (smaller packs cost more per credit),
and new accounts get 500 free credits (100 when you sign up with a free email provider such as Gmail, Outlook or Yahoo, another personal mailbox such as a paid one like Fastmail or one from your internet provider, or an address from a relay or alias service). The key's daily credit cap bounds what a burst of sign-ups can spend;
once it is reached, sign-ups go through unchecked until the cap resets.

## What we receive

The function sends only the email address, to our US or EU host. Not the person's name, IP address, user id or
anything else from Firebase.

## Related

- [Sign-up form validation](https://email-validation.org/docs/guides/signup-form-validation/)
- [Statuses and reasons](https://email-validation.org/docs/statuses/)
- [Test addresses](https://email-validation.org/docs/test-addresses/)
- [Rate limits](https://email-validation.org/docs/rate-limits/)

## More on Firebase

- [Firebase integration](https://email-validation.org/integrations/firebase/)
