Integrations · Sign-up and auth

Stop bad emails at Supabase sign-up

Keep sign-ups with bad email addresses out of a Supabase project. A small Edge Function runs as Supabase Auth's Before User Created hook: before a user is created, it checks the email address with the API and refuses the sign-up when the result is a status you chose to stop (by default invalid and disposable). The person signing up sees a message saying why. If the API is slow or down, the sign-up goes through.

It is one TypeScript file with no dependencies. Download it: index.ts.

What gets checked

Supabase Auth calls the hook whenever it is about to create a user: sign-ups with an email address and password, by magic link or email code, by phone, through OAuth providers such as Google or GitHub, through SAML single sign-on (on Supabase's Pro plan and above), and invitations you send. A sign-up without an email address (by phone, an anonymous user) goes through unchecked. Users you create yourself with auth.admin.createUser (Create new user in the dashboard) do not go through the hook.

Set it up

  1. Create an API key on the API keys page with the permission Validate addresses and a daily credit cap.
  2. Create the folder supabase/functions/email-validation-signup/ in your project and put the downloaded index.ts in it.
  3. Add this to supabase/config.toml. Supabase Auth sends no JWT to a hook, so the function must not ask for one:
    [functions.email-validation-signup]
    verify_jwt = false
  4. Deploy the function and set your key:
    supabase functions deploy email-validation-signup --no-verify-jwt
    supabase secrets set EV_API_KEY=your-api-key
  5. In the Supabase dashboard, open Authentication → Hooks → Add hook → Before User Created. Choose HTTPS, enter https://<project-ref>.supabase.co/functions/v1/email-validation-signup, click Generate secret, copy the secret and click Create.
  6. Give the function that secret:
    supabase secrets set BEFORE_USER_CREATED_HOOK_SECRET='v1,whsec_...'
    Until it has the secret, the function lets every sign-up through unchecked.

Choose what to stop

Settings are the function's secrets (supabase secrets set NAME=value, or Edge Functions → Secrets in the dashboard):

SecretValue
EV_API_KEYyour API key (required)
BEFORE_USER_CREATED_HOOK_SECRETthe hook's secret (required)
EV_STOP_STATUSESthe statuses that refuse a sign-up, separated by commas, from invalid, disposable, catch_all and unknown. Default invalid,disposable. none refuses nothing and only logs the results.
EV_DENY_MESSAGEthe message the person sees, instead of ours
EV_REGIONeu to check addresses in the EU (EU data residency)

catch_all and unknown addresses usually belong to real people: stopping them turns some real sign-ups away. A result marked disposable is refused while disposable is on the list, whatever its status (the API keeps invalid or unknown as the status of some addresses on disposable domains). An unknown result caused by a slow or failing check on our side never refuses a sign-up, marked disposable or not.

Try it

Try it without sending any mail: sign up with no_mailbox@sandbox.email-validation.org. It is refused with "This email address cannot receive email. Please check it or use another address." before Supabase creates the user, so no user is made and nothing is mailed; disposable@sandbox.email-validation.org is refused too, with its own message. Test addresses are free. Do not sign up with a test address that passes: Supabase would create the user and send its confirmation mail to a domain that receives no mail. To see a sign-up go through, use an address of your own (a normal check; Supabase mails you its confirmation).

If the check cannot be made

Supabase Auth refuses a sign-up when its hook does not answer within 5 seconds, so the function waits at most 3 seconds for the API. When there is no answer in time, the API is down or rate limited, the key is missing or wrong, or anything unexpected happens, the function tells Supabase to go on and the user is created. The function never resends a check (Supabase may call the hook again).

This covers everything the function does. While the hook is on, Supabase Auth refuses every sign-up when it cannot reach the function at all: if the function is not deployed, was deleted or renamed, was deployed without --no-verify-jwt, or fails to start. Turn the hook off in Authentication → Hooks before you remove or rename the function.

The function's logs (Edge Functions → email-validation-signup → Logs) show one line for each refused or unchecked sign-up, with the status and our request id, never the address.

Cost

Each checked sign-up uses one credit. unknown results and test addresses are free. A check cut off by the 3-second limit may still use one.

More on Supabase

Updated · Maintained by: Email Validation LLC

Need help? Contact support, or ask the help chat. Something wrong or missing on this page? Tell us