What we'll build
Apps built with Lovable usually sign users up with Supabase Auth, which accepts any address that looks right: jane@gmial.com, test@mailinator.com or a domain that doesn't exist. Those sign-ups never confirm their email, and the disposable ones are often abuse.
We'll add a check before the account is created:
- A Supabase Edge Function,
validate-email, calls the validateemail.io API. Running it on the server keeps your API key out of the browser. - The sign-up form calls the function, shows a message for invalid and disposable addresses, and offers a one-click fix for typos like
gmial.com.
If the API is slow or down, the function lets the sign-up through, so a network problem never blocks real users. Every snippet was tested with Deno 2 and React 19.
1. Store your API key
Get a free API key (250 lookups a day, no card). Then save it as a Supabase secret so the Edge Function can read it. In the Supabase dashboard, go to Edge Functions → Secrets and add VALIDATEEMAIL_KEY, or use the CLI:
supabase secrets set VALIDATEEMAIL_KEY=ev_your_api_keyNever put the key in your React code or a VITE_ variable: anything in the front end is visible to every visitor.
2. Create the Edge Function
The function takes {"email": "..."}, asks the API, and turns the result into a simple yes or no with a message. It lives in two files, so the logic can be tested without starting a server:
// Called from the browser with supabase.functions.invoke(), so it answers CORS preflights.
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "authorization, x-client-info, apikey, content-type",
};
const reply = (body: unknown, status = 200) =>
Response.json(body, { status, headers: corsHeaders });
export async function handler(req: Request): Promise<Response> {
if (req.method === "OPTIONS") return new Response("ok", { headers: corsHeaders });
const { email } = await req.json().catch(() => ({}));
if (typeof email !== "string") return reply({ error: 'Send JSON like {"email": "jane@example.com"}' }, 400);
try {
const res = await fetch("https://validateemail.io/v1/validate", {
method: "POST",
headers: {
// Set with: supabase secrets set VALIDATEEMAIL_KEY=ev_...
Authorization: `Bearer ${Deno.env.get("VALIDATEEMAIL_KEY")}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ email }),
signal: AbortSignal.timeout(5000),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const result = await res.json();
if (result.status === "invalid") {
return reply({ ok: false, message: "That email address can't receive mail.", didYouMean: result.did_you_mean });
}
if (result.checks?.disposable) {
return reply({ ok: false, message: "Please use a permanent email address.", didYouMean: null });
}
return reply({ ok: true, didYouMean: result.did_you_mean });
} catch (err) {
// Never block a sign-up because the validator is slow or unreachable.
console.warn("Email validation unavailable:", err);
return reply({ ok: true, didYouMean: null });
}
}import { handler } from "./handler.ts";
Deno.serve(handler);Deploy it:
supabase functions deploy validate-emailThe policy here rejects addresses that can't receive mail and disposable inboxes, and accepts everything else, including role accounts like info@. Change the two if blocks if your app needs something stricter.
3. Call it from your sign-up form
supabase.functions.invoke() sends the user's session token for you, so the function's default JWT check passes. Lovable projects connected to Supabase already have the client at @/integrations/supabase/client:
import { useState } from "react";
import { supabase } from "@/integrations/supabase/client";
export function SignupForm() {
const [email, setEmail] = useState("");
const [message, setMessage] = useState<string | null>(null);
const [suggestion, setSuggestion] = useState<string | null>(null);
async function onSubmit(e: React.FormEvent) {
e.preventDefault();
const { data, error } = await supabase.functions.invoke("validate-email", { body: { email } });
// If the function itself fails, don't block the sign-up.
if (!error && data && !data.ok) {
setMessage(data.message);
setSuggestion(data.didYouMean);
return;
}
setMessage(null);
// Continue the sign-up, e.g. supabase.auth.signUp({ email, password }).
}
return (
<form onSubmit={onSubmit}>
<input type="email" value={email} onChange={(e) => setEmail(e.target.value)} required />
{message && <p role="alert">{message}</p>}
{suggestion && (
<button type="button" onClick={() => setEmail(suggestion)}>
Did you mean {suggestion}?
</button>
)}
<button type="submit">Sign up</button>
</form>
);
}If the function itself errors, the form carries on with the sign-up. Only a clear "no" from the validator stops it.
Or let Lovable write it for you
Using an AI coding assistant? Paste this prompt and it will wire up the API for you:
Add email validation to the sign-up form of this Lovable app. Do the API call in a Supabase Edge Function named validate-email (the key is the Supabase secret VALIDATEEMAIL_KEY) and call that function from the form using the validateemail.io API (reference: https://validateemail.io/llms.txt).
- Call POST https://validateemail.io/v1/validate from server-side code only, with the header "Authorization: Bearer <key>" read from the VALIDATEEMAIL_KEY environment variable, and the JSON body {"email": "<address>"}. Never call it from the browser.
- Reject the address with a clear message when "status" is "invalid" or "checks.disposable" is true.
- When "did_you_mean" is set, show "Did you mean <did_you_mean>?" and let the user accept the fix.
- Use a 5-second timeout. If the API fails, times out or returns "status": "unknown", accept the address so sign-ups never break.
- Add a test that mocks the API for a valid, an invalid and a disposable address.Add the VALIDATEEMAIL_KEY secret first (step 1), so the function works as soon as Lovable deploys it.
Test it
Because the logic is in handler.ts, you can test it with Deno and a stubbed API, without deploying anything:
// Harness: the function against a stubbed API, run with `deno test --allow-env`.
import { handler } from "./handler.ts";
function assertEquals(actual: unknown, expected: unknown) {
if (JSON.stringify(actual) !== JSON.stringify(expected)) throw new Error(`${JSON.stringify(actual)} !== ${JSON.stringify(expected)}`);
}
const api = (body: unknown, status = 200) => {
globalThis.fetch = (async () => Response.json(body, { status })) as typeof fetch;
};
const call = async (email: unknown) =>
(await handler(new Request("http://localhost/validate-email", { method: "POST", body: JSON.stringify({ email }) }))).json();
Deno.test("valid address", async () => {
api({ status: "valid", reason: "mail_server_found", did_you_mean: null, checks: { disposable: false } });
assertEquals(await call("jane@gmail.com"), { ok: true, didYouMean: null });
});
Deno.test("typo is suggested but accepted", async () => {
api({ status: "risky", reason: "possible_typo", did_you_mean: "joe@gmail.com", checks: { disposable: false } });
assertEquals(await call("joe@gamil.com"), { ok: true, didYouMean: "joe@gmail.com" });
});
Deno.test("invalid and disposable are rejected", async () => {
api({ status: "invalid", reason: "domain_not_found", did_you_mean: null, checks: { disposable: null } });
assertEquals((await call("x@no-such-domain.example")).ok, false);
api({ status: "risky", reason: "disposable", did_you_mean: null, checks: { disposable: true } });
assertEquals(await call("t@mailinator.com"), { ok: false, message: "Please use a permanent email address.", didYouMean: null });
});
Deno.test("fails open when the API is down", async () => {
api({ error: {} }, 503);
assertEquals(await call("jane@gmail.com"), { ok: true, didYouMean: null });
});
Deno.test("answers CORS preflight and bad input", async () => {
const pre = await handler(new Request("http://localhost/validate-email", { method: "OPTIONS" }));
assertEquals(pre.headers.get("access-control-allow-origin"), "*");
assertEquals((await handler(new Request("http://localhost/x", { method: "POST", body: "{}" }))).status, 400);
});Run it with deno test --allow-env. To try the real thing, run supabase functions serve and sign up with test@mailinator.com.
What if my app has no back end?
If your app is purely static, you can't hide a secret key. Create a browser key instead: it only works from your site's domain and only validates one address per request, so it's safe in front-end code. Call /v1/validate from the form with Authorization: Bearer pk_… and apply the same rules as the function above.
Frequently asked questions
Does Supabase Auth validate email addresses?
Supabase Auth checks the format and, with email confirmation on, sends a confirmation link. It doesn't reject domains that don't exist, disposable inboxes or typos like gmial.com before the account is created, which is what the Edge Function in this guide adds.
Where do I put the API key in a Lovable app?
In a Supabase secret (Edge Functions → Secrets), read in the Edge Function with Deno.env.get("VALIDATEEMAIL_KEY"). Never in React code or a VITE_ environment variable, which end up in the browser.
Will this slow down sign-up?
Usually by a few hundred milliseconds, once per sign-up. The function gives up after 5 seconds and lets the sign-up through, so a slow or unreachable API never blocks a real user.
Can I block disposable emails in Lovable without code?
Paste the prompt above into Lovable and it will write the Edge Function and the form change for you. You only need to add the VALIDATEEMAIL_KEY secret.