Supabase · TypeScript (Deno)
Block disposable email in Supabase
Use a Supabase Edge Function as an Auth Hook. Calls Piisend before Supabase creates the user — rejects signup at the auth layer.
The code
// supabase/functions/before-user-created/index.ts
import { Webhook } from "https://esm.sh/standardwebhooks@1.0.0";
const CHECK_URL = "https://api.piisend.com/api/v1/check/email";
async function shouldBlock(email: string): Promise<boolean> {
try {
const r = await fetch(`${CHECK_URL}/${encodeURIComponent(email)}`, {
headers: {
Authorization: `Bearer ${Deno.env.get("PIISEND_API_KEY")}`,
},
});
if (!r.ok) return false;
const data = await r.json();
// reject on 'block' — catches disposable, spam, no-MX and typo'd addresses
return data.recommendation === 'block';
} catch {
return false;
}
}
Deno.serve(async (req) => {
const payload = await req.text();
const headers = Object.fromEntries(req.headers);
const wh = new Webhook(Deno.env.get("SUPABASE_AUTH_HOOK_SECRET")!);
const { user } = wh.verify(payload, headers) as { user: { email?: string } };
if (user.email && await shouldBlock(user.email)) {
return new Response(
JSON.stringify({ error: { message: "Please use a permanent email address.", http_code: 400 } }),
{ status: 400 },
);
}
return new Response(JSON.stringify({}), { status: 200 });
});API key
Set `PIISEND_API_KEY` as a Supabase Edge Function secret via `supabase secrets set`.
Fail-open vs fail-closed
Returns allow on API errors — tune for your fraud tolerance.
Pair with verification
Register the function as a "Before user created" auth hook in the Supabase dashboard.
FAQ
Where does the Piisend API key go in Supabase?
Set `PIISEND_API_KEY` as a Supabase Edge Function secret via `supabase secrets set`.
What happens if Piisend is slow or down?
Returns allow on API errors — tune for your fraud tolerance.
How does this fit with the rest of Supabase signup?
Register the function as a "Before user created" auth hook in the Supabase dashboard.
What does this snippet block?
Addresses on disposable domains: about 10,900 listed domains, plus new ones whose mail servers belong to a known throwaway service. Free providers such as Gmail and forwarding aliases such as duck.com pass.
Can I get a full allow / review / block verdict instead?
Yes, and we recommend it. Call GET /api/v1/check/email/{email} instead. Both endpoints need an API key with the check:read scope and use one check from your monthly allowance per call, but the check endpoint also returns forwarding relays, phishing lists, missing MX records, new domains, typo suggestions and an allow / review / block verdict.
Send verification email with Piisend
After blocking disposable addresses, send OTP and verification mail through the same Piisend account. One API key for intelligence checks and transactional sends.