Better Auth
import { betterAuth } from "better-auth";
export const auth = betterAuth({
hooks: {
before: {
signUp: async (ctx) => {
const { email } = ctx.body;
try {
const r = await fetch(
`https://api.disposableguard.com/v1/check?email=${encodeURIComponent(email)}`,
{
headers: {
Authorization: `Bearer ${process.env.DG_KEY}`,
},
}
);
if (r.ok) {
const data = await r.json();
if (data.is_disposable) {
throw new Error("Please use a real email address.");
}
}
} catch (e: any) {
if (e.message === "Please use a real email address.") throw e;
// fail-open
}
},
},
},
});Notes
Uses Better Auth hooks to intercept the signup flow before user creation.