Skip to content

feat: welcome email via Vercel API route + DB trigger#990

Open
orveth wants to merge 1 commit intomasterfrom
feat/welcome-email-api
Open

feat: welcome email via Vercel API route + DB trigger#990
orveth wants to merge 1 commit intomasterfrom
feat/welcome-email-api

Conversation

@orveth
Copy link
Copy Markdown
Contributor

@orveth orveth commented Apr 10, 2026

Summary

  • Adds a React Router resource route (/api/welcome-email) that sends welcome emails via Resend when called by a Supabase DB trigger
  • Replaces the previous Edge Function approach with a Vercel-hosted endpoint for unified deployment and monitoring
  • Includes idempotency (Resend Idempotency-Key header) to prevent duplicate sends

Files

  • app/routes/api.welcome-email.ts — POST endpoint, validates webhook secret, calls Resend API
  • supabase/migrations/20260410120000_welcome_email_webhook.sql — DB trigger on wallet.users INSERT

Configuration needed

Vercel env vars (all environments)

  • WEBHOOK_SECRET — shared secret for authenticating DB trigger calls
  • RESEND_API_KEY — Resend API key (use per-environment keys)
  • RESEND_WELCOME_TEMPLATE_ID — Resend template ID (51320094-3fc9-416f-9c4a-de4fff0fc5e2)

Supabase vault secrets (per environment)

After applying the migration, run in the SQL editor:

select vault.create_secret('https://your-app-url.vercel.app', 'webhook_base_url');
select vault.create_secret('your-webhook-secret-value', 'webhook_secret');

Resend

  • Domain emails.agi.cash must be verified (already done)
  • Template must be published (already done — bob updated it)

How it works

  1. New user inserted into wallet.users (with email)
  2. Postgres trigger fires wallet.handle_new_user()
  3. Trigger reads vault secrets and calls POST /api/welcome-email via pg_net
  4. API route validates the webhook secret, then calls Resend API with idempotency key
  5. User receives welcome email

Guest signups (no email) are skipped. Upsert-updates don't trigger (INSERT ON CONFLICT DO UPDATE fires UPDATE, not INSERT).

Supersedes

This replaces PR #980 (Edge Function approach). That PR can be closed after this merges.

🤖 Generated with Claude Code

API route receives POST from Supabase pg_net trigger, validates auth
and payload with zod, then calls Resend API with idempotency key to
send the welcome email. DB migration creates trigger on wallet.users
that fires on INSERT, reads secrets from vault, and posts to the API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agicash Ready Ready Preview, Comment Apr 10, 2026 11:18pm

Request Review

@supabase
Copy link
Copy Markdown

supabase bot commented Apr 10, 2026

Updates to Preview Branch (feat/welcome-email-api) ↗︎

Deployments Status Updated
Database Fri, 10 Apr 2026 23:17:40 UTC
Services Fri, 10 Apr 2026 23:17:40 UTC
APIs Fri, 10 Apr 2026 23:17:40 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations ⚠️ Fri, 10 Apr 2026 23:19:59 UTC
Migrations Fri, 10 Apr 2026 23:20:02 UTC
Seeding Fri, 10 Apr 2026 23:20:02 UTC
Edge Functions Fri, 10 Apr 2026 23:20:02 UTC

⚠️ Warning — Service health check failed


View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants