// auth and identity
Via APIBetter Auth email verification with pingutil
Better Auth stores whatever address arrives at /sign-up/email, and requiring email verification still lets a temp-mail inbox click the link. A hooks.before middleware that calls pingutil rejects disposable, dead and mistyped addresses with an APIError the client can show, and a databaseHooks.user.create.before hook covers social and other sign-up paths.
Where it connects: Better Auth hooks.before on /sign-up/email, plus databaseHooks.user.create.before for every sign-up method
What goes wrong without it
- Our Better Auth users table has hundreds of rows at mailinator-style domains, all on the free tier.
- People typo their address at sign-up, never get the verification email and we cannot reach them.
- The example in the docs only checks a fixed domain suffix, and we do not want to maintain a disposable list in our repo.
What you can do with Better Auth and pingutil
Reject throwaway and dead addresses on email sign-up
In hooks.before, when ctx.path is /sign-up/email, call /v1/verify. Status invalid (disposable_domain, mailbox_not_found, no_mx) throws APIError BAD_REQUEST and Better Auth never writes the user.
Return the typo suggestion to the form
did_you_mean carries the likely address, for example jane@gmail.com for jane@gmial.com. Put it in the APIError message so the sign-up form can offer the fix.
Cover social sign-ups at user creation
databaseHooks.user.create.before runs for every new user. Use fast-mode /v1/lookup there and return false to abort creation when verdict.is_spam is true.
Set it up
- 1
Create a pingutil API key in the pingutil dashboard and add it to your server environment as PINGUTIL_KEY.
- 2
Add the checkEmail helper below next to your Better Auth config.
- 3
Add the hooks.before middleware with createAuthMiddleware and return early for any path other than /sign-up/email.
- 4
Add databaseHooks.user.create.before so users created through other methods get the fast check too.
- 5
Sign up with a disposable address and confirm the client receives the BAD_REQUEST error message.
import { betterAuth } from 'better-auth';
import { createAuthMiddleware, APIError } from 'better-auth/api';
async function pingutil(path: string, body: object, timeoutMs: number) {
try {
const res = await fetch('https://pingutil.com' + path, {
method: 'POST',
headers: {
authorization: 'Bearer ' + process.env.PINGUTIL_KEY,
'content-type': 'application/json',
},
body: JSON.stringify(body),
signal: AbortSignal.timeout(timeoutMs),
});
return res.ok ? await res.json() : null; // 429 or 5xx: fail open
} catch {
return null; // timeout or network error: fail open
}
}
export const auth = betterAuth({
// ...database, emailAndPassword, socialProviders
hooks: {
before: createAuthMiddleware(async (ctx) => {
if (ctx.path !== '/sign-up/email') return;
const email = ctx.body?.email;
if (typeof email !== 'string') return;
// Mailbox check: catches disposable, dead mailboxes and typos.
const v = await pingutil('/v1/verify', { email }, 4000);
if (v?.status === 'invalid') {
const hint = v.did_you_mean ? ' Did you mean ' + v.did_you_mean + '?' : '';
throw new APIError('BAD_REQUEST', {
message: 'Please use a real, permanent email address.' + hint,
});
}
}),
},
databaseHooks: {
user: {
create: {
// Runs for every new user, including social sign-ups.
before: async (user) => {
const r = await pingutil('/v1/lookup', { input: user.email, skip_enrichment: true }, 1500);
if (r?.verdict?.is_spam) return false; // abort creation
},
},
},
},
});What to do with each result
| pingutil result | Action in Better Auth |
|---|---|
| status: "invalid", reason "disposable_domain" | Throw APIError BAD_REQUEST asking for a permanent address |
| status: "invalid" with did_you_mean set | Throw APIError with the suggested address in the message |
| status: "risky" (accept_all, role_based, randomized_local_part) | Allow; store the reason on the user for later review if you need it |
| verdict.is_spam: true in databaseHooks | Return false to abort user creation |
| Timeout, 429 or 5xx | The helper returns null and sign-up continues (fail open) |
Limits to plan for
- A mailbox check on a slow server can take several seconds, and the user waits on the sign-up request. Keep the timeout short, or call fast-mode /v1/lookup in hooks.before as well if latency matters more than catching dead mailboxes.
- Better Auth notes that before hooks can run more than once on MongoDB with transactions, because the adapter retries. A second call for the same address is usually a pingutil cache hit, but it still counts toward your lookups.
- Every check counts toward 300 verified addresses a day (3,000 a month) or 2,000 lookups a day (30,000 a month) per account. Those are Free plan limits; Enterprise has custom limits.
Better Auth documentation
Better Auth is a trademark of its owner. This integration uses Better Auth's documented extension points; it is not an official Better Auth app.
Common questions
- Why both hooks.before and databaseHooks?
- hooks.before on /sign-up/email can throw an APIError with a message the form shows. databaseHooks.user.create.before runs for every user creation, including social sign-ups, but returning false there gives the user a generic failure, so it suits the fast disposable check.
- Does this replace Better Auth email verification?
- No. Keep requireEmailVerification if you use it. pingutil stops throwaway and dead addresses before the account exists; the verification email still proves the person controls the inbox.
Stop bad addresses in Better Auth today
Sign in with your email, create an API key and paste it into the step above. Test on a few real addresses first: the live demo shows exactly what your Better Auth setup will receive.