Skip to content
Vibe Coding Engineer

Vibe Coding Engineer

Free Code Hustle

  • AI Tools
  • Vibe Coding
  • Tutorials & Guides
  • Prompt Engineering
  • About
  • Contact
Vibe Coding Engineer

Vibe Coding Engineer

Free Code Hustle

  • AI Tools
  • Vibe Coding
  • Tutorials & Guides
  • Prompt Engineering
  • About
  • Contact
  • Home
  • Tutorials & Guides
  • How to Add Email (Magic Links + Transactional) to a Vibe-Coded Stack
  • shadcn/ui + AI: Prompts That Keep Components Consistent Across Pages
  • How to Add Email (Magic Links + Transactional) to a Vibe-Coded Stack
  • Devin AI Review 2026: Is the Autonomous Software Engineer Worth It Yet?
  • Designing Admin Dashboards With AI: Patterns That Don’t Look Generic
  • Vibe Coding Launch Checklist: 25 Things to Fix Before You Share the Link
Secure authentication and database setup for Supabase prompts
November 25, 2026 · 9 min read · 10 views

How to Add Email (Magic Links + Transactional) to a Vibe-Coded Stack

Adding email to a vibe-coded stack — magic links for login and transactional messages for receipts — is where demos die in spam folders and Supabase auth callbacks 404 on wrong domains. AI agents wire Resend or SendGrid in ten minutes and skip DKIM, redirect URLs, and idempotent welcome sends. This tutorial walks magic link auth plus transactional patterns for Next.js App Router with production checks. Updated November 2026.

Email authentication flow diagram with magic link and transactional messages in a Next.js SaaS application
Email is infrastructure — deliverability and callback URLs matter as much as the React button.

Prerequisites: working app shell from the vibe coding roadmap, auth baseline from add auth to a vibe-coded Next.js app, and deploy on custom domain via deploy to Vercel. Run the launch checklist item on email before public beta.

Table of contents

  1. Email architecture choices
  2. Step 1 — Provider and domain setup
  3. Step 2 — Magic link auth flow
  4. Step 3 — Transactional templates
  5. Step 4 — Server routes and security
  6. Step 5 — Testing and deliverability
  7. AI-generated email bugs
  8. FAQ

Email architecture choices

2026 vibe stacks usually pick:

  • Supabase Auth magic links — auth sends email; you customize SMTP or use Supabase defaults (limited branding)
  • NextAuth / Auth.js + Resend — full control of template and provider
  • Clerk / WorkOS — hosted auth emails included — less tutorial focus here
  • Resend + custom token — roll your own magic link (only if you understand JWT expiry)
PatternProsCons
Supabase built-in magic linkFast; integrates with RLS userTemplate control limited on free tier
Auth.js Email provider + ResendFlexible templates, Next-nativeMore config surface
Custom magic tokenTotal controlEasy to get crypto wrong

This guide emphasizes Supabase Auth magic links plus Resend for transactional (welcome, invoice, alert) — common solo stack.

Step 1 — Provider and domain setup

  1. Create Resend account; verify sending domain (subdomain like mail.yourdomain.com recommended)
  2. Add DNS records: SPF, DKIM, optional DMARC — wait for green check in dashboard
  3. Store RESEND_API_KEY in Vercel production and preview env (different keys if desired)
  4. Set NEXT_PUBLIC_SITE_URL to production URL — auth callbacks depend on it
  5. In Supabase Dashboard → Authentication → URL Configuration: set Site URL and redirect allowlist

Prompt: “Configure Supabase auth redirect URLs for https://app.example.com/auth/callback. Add RESEND_API_KEY server-only. Do not expose keys in client components.”

Step 2 — Magic link auth flow

Supabase magic link flow:

  1. User enters email on login page
  2. Client calls supabase.auth.signInWithOtp({ email, options: { emailRedirectTo } })}
  3. User clicks link in email; Supabase validates token
  4. Callback route exchanges session; redirect to dashboard
  5. Middleware refreshes session cookie on subsequent requests

Critical emailRedirectTo must match allowlist exactly — including trailing slash consistency. AI often hardcodes localhost; production magic links then fail silently.

Custom SMTP: Supabase → Project Settings → Auth → SMTP with Resend credentials for branded auth emails. Template variables documented in Supabase auth email docs.

Resend dashboard showing verified domain DNS records for transactional email deliverability
No verified domain — no reliable magic links. Fix DNS before polishing login UI.

Step 3 — Transactional templates

Separate auth emails from product emails:

  • Welcome — after first signup (trigger from webhook or post-confirm route once)
  • Receipt / invoice — after Stripe checkout.session.completed
  • Alerts — usage threshold, failed payment — tie to Stripe webhooks
  • Support ack — contact form received

Resend React Email pattern in Next.js:

  • Templates in emails/Welcome.tsx using @react-email/components
  • Server route or server action calls resend.emails.send({ from, to, subject, react: WelcomeEmail({ name }) })
  • From address on verified domain: hello@mail.yourdomain.com

Idempotency: store welcome_sent_at on user row — webhook retries must not send five welcomes. Same lesson as Stripe webhook idempotency.

Step 4 — Server routes and security

  • Send email only from server — API route, server action, or Edge Function
  • Rate limit /api/auth/magic-link and contact endpoints per IP and email
  • Validate email format; do not leak “user not found” vs “sent” if enumeration matters — uniform success message
  • Log message id from Resend; never log full magic link URLs in production logs
  • Admin “resend welcome” behind role check

Cross-check auth middleware from the auth tutorial — email login does not replace session checks on dashboard routes.

Step 5 — Testing and deliverability

  1. Send test to Gmail, Outlook, and one mobile client
  2. Check spam placement — missing DKIM is the usual culprit
  3. Click magic link on mobile mail app — session persists in app browser
  4. Test expired link error copy
  5. Stripe test payment → confirm receipt email within 60 seconds

Use Resend logs for bounces; suppress repeated sends to hard bounces. Add monitoring alert if send error rate spikes.

AI-generated email bugs

BugSymptomFix
RESEND_API_KEY in clientKey scraped from bundleServer-only import
Wrong redirect URLMagic link lands on 404Site URL + allowlist sync
No idempotency on welcomeDuplicate emails on webhook retryDB flag before send
From noreply@gmail.comSpam folderVerified custom domain
HTML-only broken on mobileUgly plaintext fallbackReact Email + preview text

Wire CI smoke test that mocks Resend in AI code tests — assert send called once per event.

Alternatives: Postmark, SendGrid, AWS SES

Resend wins vibe-coding tutorials for DX; Postmark excels deliverability support; SES wins at scale on AWS. Switching cost is mostly template port and env vars — keep send logic behind one sendEmail() wrapper your agent does not duplicate per feature.

Compliance and unsubscribe

Transactional emails (receipts, magic links) generally skip marketing unsubscribe — product emails blurring into newsletters need List-Unsubscribe headers and consent. When in doubt, separate marketing@ subdomain from auth@ and billing@.

Custom SMTP for Supabase auth emails

Default Supabase email works for first login test; production branding needs custom SMTP. Resend SMTP credentials in Supabase auth settings:

  • Host, port, user, password from Resend SMTP docs
  • Sender email on verified domain
  • Customize magic link template with product name and support link
  • Test OTP expiry message renders in plain text fallback

Prompt: “Configure Supabase to use custom SMTP for auth emails. Keep magic link template minimal — product name, one sentence, single CTA button styled inline CSS only. No external stylesheet links in email HTML.”

Connecting Stripe webhooks to email

Receipt email belongs in webhook handler after idempotency check:

  1. Verify Stripe signature on raw body
  2. Parse checkout.session.completed
  3. Lookup user by customer id; check receipt_sent_at null
  4. Send React Email template with line items from session
  5. Set receipt_sent_at before returning 200

Duplicate webhook delivery without idempotency spams users — same pattern as payment state bugs in Stripe tutorials. Cross-read payment prompts for event types beyond checkout if you use subscriptions.

Local development email traps

Localhost magic links fail on phones unless tunneling. Options:

  • Mailpit / Inbucket — catch emails locally without sending
  • ngrok or Cloudflare tunnel — test real links on device
  • Staging deploy — authoritative pre-prod email QA

AI agents hardcode http://localhost:3000 in emailRedirectTo — grep before every production deploy. Add CI check that fails if localhost appears outside test files.

Monitoring email health

SignalToolAction threshold
Bounce rateResend dashboardInvestigate if >2% daily
Auth email latencySupabase logsAlert if p95 >30s
Magic link click-throughProduct analyticsDrop may mean spam folder
Send API errorsSentry on server routePage on 5xx spike

Transactional template library

Standardize templates early — agents invent new HTML per email otherwise:

TemplateTriggerKey fields
MagicLinkAuth OTPexpiry note, support email
WelcomeFirst signupfirst action CTA deep link
Receiptcheckout.session.completedamount, last4, manage billing link
PaymentFailedinvoice.payment_failedupdate payment method URL
ContactAckForm submitexpected response time

Store in emails/ with shared Layout wrapper — logo, footer address, unsubscribe only on marketing subset. Prompt: “All transactional emails use emails/components/Layout.tsx — no standalone HTML documents.”

Auth.js Email provider alternative

Not on Supabase Auth? Auth.js with Resend provider:

  1. Install @auth/core and configure Email provider
  2. Custom sendVerificationRequest calling Resend SDK
  3. Session strategy JWT or database per your stack
  4. Align AUTH_URL with production domain

Same DNS and rate-limit rules apply. Choose one auth email path — dual systems send duplicate magic links and confuse users.

Deliverability deep checks before launch

Beyond DNS green checks:

  • Send from subdomain (mail.domain.com) — protects root domain reputation if marketing spams later
  • Set DMARC p=none initially, move to quarantine after week of clean sends
  • Avoid link shorteners in auth emails — spam filters flag them
  • Plain text part included — multipart/alternative in Resend templates
  • Preview text in template — not empty or “View in browser” only

Seed Gmail Postmaster Tools for domain when volume exceeds fifty daily — early reputation data prevents crisis mode at growth spike.

Marketing vs transactional separation

Adding newsletter checkbox at signup? Split infrastructure:

  • Transactional: auth, receipts — no unsubscribe required; send regardless of marketing opt-out
  • Marketing: product updates — separate list in Resend Audiences or provider equivalent
  • Never mix — unsubscribing from newsletter must not block magic links

Prompt agents explicitly: “Welcome email is transactional post-confirm only. Newsletter uses separate double opt-in flow.” One conflated stream creates legal and deliverability mess.

FAQ

Magic link or password for B2B SaaS?

Magic links reduce support burden; some enterprises prefer SSO later. Start magic link; add Google OAuth when requested.

Can I use Resend free tier for production?

Often yes at low volume — verify current limits and domain verification requirements.

Supabase email rate limits?

Built-in provider throttles; custom SMTP via Resend raises ceiling — monitor abuse on public signup forms.

How long should magic links last?

Supabase defaults are documented in auth settings — balance UX vs security; never infinite.

Why do emails work locally but not on Vercel?

Missing env vars on production, or Site URL still localhost in Supabase dashboard.

Should I use Edge or Node runtime for send?

Node serverless for Resend SDK compatibility unless docs specify edge — verify before shipping.

Can I use one Resend account for multiple projects?

Yes — separate domains per project; never share verified domain between unrelated brands without tracking reputation separately.

What about SendGrid or Amazon SES?

Same architecture — magic link plus transactional split, DNS verification, server-only keys. Resend examples port directly with SDK swap.

Email completes the auth and revenue loop — without deliverability, the rest of your vibe-coded stack is a local demo with a custom domain. Treat DNS and callback URLs as launch blockers equal to RLS.

Soft CTA: Verify your domain in Resend tonight, send one magic link to your phone, and click it on cellular data — not WiFi localhost fantasy. Then add one transactional template tied to a real Stripe test event. Email done right is invisible; email done wrong is your entire launch.

Related reading on Vibe Coding Engineer

Continue with the vibe coding roadmap, the 2026 starter stack, and the Month 2 reading list. Each guide is written for builders who want outcomes, not hype — Free Code Hustle style. Bookmark this page and ship the next thin slice before you open another tab of tool comparisons.

When you are ready for monetization and ops, pair this article with Month 3 hubs on payments, security, and production monitoring. The goal is a compounding library: every post should make the next deploy safer, faster, or more useful to a real user.

Tagged: magic link email ai app resend email nextjs vibe coding transactional email lovable

Post navigation

Previous: Devin AI Review 2026: Is the Autonomous Software Engineer Worth It Yet?
Next: shadcn/ui + AI: Prompts That Keep Components Consistent Across Pages

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related News

Developer starter stack setup with laptop and notebook

Vibe Coding Launch Checklist: 25 Things to Fix Before You Share the Link

Mazhar Ali4 days ago2 months ago 1 21 views
Secure authentication and database setup for Supabase prompts

How to Add File Uploads to a Vibe-Coded App (Supabase Storage Step-by-Step)

Mazhar Ali1 week ago2 months ago 0 19 views
Analytics dashboard and search console for website launch

How to Get Google AdSense Approved for a Niche Tech Blog in 2026

Mazhar Ali2 weeks ago2 months ago 0 25 views
Reading list roadmap after shipping first AI-built app

After Your First AI-Built App: 10 Posts to Read Next (Month 2 Reading List)

Mazhar Ali2 weeks ago2 months ago 1 32 views
© 2025 - Vibe Coding Engineers Powered By BlazeThemes.
  • About Us
  • Contact
  • Terms & Conditions
  • Privacy Policy