Firebase Auth
// functions/src/blockDisposable.js
const functions = require("firebase-functions/v2");
const admin = require("firebase-admin");
admin.initializeApp();
exports.beforeUserCreated = functions.identity.beforeUserCreated(
async (event) => {
const { email } = event.data;
if (!email) return;
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 https.HttpsError(
"invalid-argument",
"Please use a real email address."
);
}
}
} catch (e) {
if (e.code) throw e;
// fail-open
}
}
);Notes
Deploy as a Firebase Cloud Function (Identity trigger). Add `DG_KEY` to Firebase config.