Secure Template-Request Flow — Serverless OTP Email Verification
Live in production, confirmed end-to-endProblem
A plain "email us" link on the WordPress template gallery invites spam and gives no proof the requester owns the address. Needed verified delivery with zero standing account infrastructure.
Approach
Two Firebase Cloud Functions (2nd-gen, europe-west1), gated by App Check (reCAPTCHA Enterprise) since the endpoints are public and unauthenticated. Firestore holds OTP state only: SHA-256 hashed codes, single-use, 10-minute expiry, 60-second resend cooldown, 5-attempt cap, and the document ID itself is a hash of the email, so no plaintext address sits in the database at rest. Firestore rules deny all client reads and writes; only the Admin SDK inside the Functions can touch the collection. Delivery runs through Resend on a dedicated sending subdomain, its own isolated team separate from other projects' mail infrastructure.
Outcome
Confirmed working end-to-end in production: template selected, email entered, OTP requested, verified, and the request email delivered via Resend. Three separate infrastructure issues stood between deploy and a working flow, a missing Cloud Build IAM role, a Domain Restricted Sharing policy silently blocking Cloud Run's public-invoker grant, and a corrupted API key from a masked terminal prompt, each only surfacing once the last one was fixed.
Stack: Next.js (static export), Firebase Cloud Functions (2nd-gen), Firestore, Firebase App Check (reCAPTCHA Enterprise), Resend
