Auth0 · JavaScript
Block disposable email in Auth0
Use an Auth0 Pre User Registration Action. Runs synchronously before Auth0 creates the user — return api.access.deny() to reject at the auth layer.
The code
/**
* Auth0 Action — Login / Post Login > Pre User Registration
* Add PIISEND_API_KEY to Action Secrets
*/
const CHECK_URL = "https://api.piisend.com/api/v1/check/email";
exports.onExecutePreUserRegistration = async (event, api) => {
const email = event.user.email;
if (!email) return;
try {
const res = await fetch(`${CHECK_URL}/${encodeURIComponent(email)}`, {
headers: {
Authorization: `Bearer ${event.secrets.PIISEND_API_KEY}`,
},
});
if (res.ok) {
const data = await res.json();
// reject on 'block' — catches disposable, spam, no-MX and typo'd addresses
if (data.recommendation === 'block') {
api.access.deny("Please use a permanent email address.");
}
}
} catch (e) {
// fail open — omit deny on error
}
};API key
Add `PIISEND_API_KEY` under Action Secrets in the Auth0 dashboard.
Fail-open vs fail-closed
Omit `api.access.deny` when fetch fails unless your policy requires fail-closed.
Pair with verification
Deploy the Action to Pre User Registration and test with a known disposable domain.
FAQ
Where does the Piisend API key go in Auth0?
Add `PIISEND_API_KEY` under Action Secrets in the Auth0 dashboard.
What happens if Piisend is slow or down?
Omit `api.access.deny` when fetch fails unless your policy requires fail-closed.
How does this fit with the rest of Auth0 signup?
Deploy the Action to Pre User Registration and test with a known disposable domain.
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.