MELLEPRISE MELLEPRISE AI MP Blog
← All articles

supabase email templates not working? Production fix

Pastel comic of email templates turning into secure login links moving through an SMTP checkpoint

Your supabase email templates looked correct when you saved them. Then real users cannot confirm signup, the magic link lands on localhost, password recovery says the link expired, or the button in the email points to the wrong environment.

This is usually not an email-design problem. It is a production-link problem. A Supabase email template sits between Auth, redirect allowlists, SMTP delivery, spam filtering, corporate link scanners and the browser state of the user.

What the failure looks like

  • The user receives the email, but the button opens Supabase instead of your app.
  • The link points to localhost, a Preview deployment, an old domain or the wrong language version.
  • The user sees otp_expired, a 403, or a generic invalid-link page even though they clicked quickly.
  • The template preview looks right, but the real email contains a missing variable, escaped HTML or a broken URL.
  • Signup works in one flow and fails in another because confirmation, invite, magic link and recovery use different templates.
  • Custom SMTP was configured, yet production sends only a handful of messages or the provider logs show suppression.

Do not rewrite the whole template first. Identify which layer changed the link before the user clicked it.

supabase email templates production click path

  1. Save the exact failing email. Keep the subject, template type, recipient, UTC time, the visible link target and the final browser URL after redirects. “The email does not work” is not precise enough.
  2. Name the template type. Confirm signup, invite, magic link, recovery, email change and reauthentication are separate templates. Editing the signup template does not repair password recovery.
  3. Test with a real inbox, not only the editor. Trigger the exact flow with a test user. Open the message in the same kind of inbox your users have, ideally including a corporate Microsoft or Google Workspace inbox.
  4. Decide between ConfirmationURL and token_hash deliberately. For the normal hosted confirmation flow, {{ .ConfirmationURL }} is the safe default because Supabase builds the correct confirmation URL. For a custom server-side or PKCE confirm page, build the URL with {{ .TokenHash }}, the correct type and a safe next value.
  5. Check RedirectTo and SiteURL as separate values. {{ .SiteURL }} is the project site URL. {{ .RedirectTo }} is the redirect target passed by the app. If you hard-code SiteURL, you can ignore the app’s intended environment and send production users to the wrong place.
  6. Compare the redirect allowlist. The final target must be allowed exactly or by a documented wildcard pattern. If the app sends users to a new domain, locale path or deep link, add that form before blaming the template.
  7. Inspect raw HTML, not only the visual editor. Look for escaped braces, spaces inside variables, tracking parameters inserted around the href, missing quotes, or a button whose visible text is correct while its href is wrong.
  8. Use the correct variable for the correct purpose. {{ .Token }} is the one-time code for OTP-style templates such as reauthentication. It is not a general-purpose URL fragment. {{ .TokenHash }} is for verify-links you intentionally construct. {{ .Email }} and {{ .NewEmail }} are user data, not login mechanisms.
  9. Check the Auth event before the SMTP provider. Supabase Auth logs can show whether the email was handed over. The SMTP provider then shows accepted, deferred, bounced, suppressed or delivered. Those are different failures and need different fixes.
  10. Measure the custom SMTP path. Custom SMTP normally starts with a low hourly sending allowance. If a burst of signups, invites or tests crosses it, later emails disappear even though earlier tests worked. Compare the pattern with supabase smtp.
  11. Account for link scanners. Corporate security tools can open the email link before the user does. A one-time confirmation or recovery link can be consumed by the scanner, so the real user then sees an expired link. Prefer PKCE/token-hash confirm pages or OTP entry for sensitive flows when this appears. This overlaps with the recovery-chain problem in supabase reset password.
  12. Remove link tracking for auth links. Some SMTP or marketing tools rewrite every link for click tracking. That can alter query parameters, strip fragments or pre-click the URL. Auth links are not campaign links; exclude them from tracking where possible.
  13. Test the browser flow after the click. PKCE uses browser-bound state. A link opened in a different browser, inside a privacy webview, or after a router guard strips the query can fail even when the template was correct.
  14. Keep a safe fallback. If you customize heavily, keep a known-good template copy for each email type. Restore it when production login is down, then reapply branding in small steps.
  15. Verify every email type separately. Signup confirmation, invite, magic link, recovery, email change and reauthentication each need one real test. Passing one does not prove the others.

The mistakes AI builders repeat

The AI designs pixels before semantics. A beautiful button is useless when the href is wrong. In auth email, the URL contract matters more than the layout. Build the plain correct link first, then style it.

The AI copies a template from another flow. A password-reset example is not automatically correct for signup or magic-link login. The type parameter is different, and the expected page after verification is different.

The AI hard-codes the production domain. That makes Preview, staging and local tests lie. Use environment-aware application URLs and redirect targets. Your production template should not need a different secret domain pasted into it.

The AI treats Token as a magic string. OTP, token hash and confirmation URL are not interchangeable. Mixing them produces emails that look plausible and fail only when real users click.

The AI forgets that email is hostile infrastructure. Spam filters rewrite links, scanners prefetch them, mobile mail clients open embedded browsers, and users forward messages.

A safe template pattern

For a normal hosted-flow button, the minimal pattern is intentionally boring:

<p><a href="{{ .ConfirmationURL }}">Confirm your email</a></p>

For an application-controlled PKCE confirm page, the shape is closer to this:

{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=email&next={{ .RedirectTo }}

The exact type depends on the flow: signup confirmation, recovery, invite, magic link or email change are not the same. Do not copy the line blindly; map it to the template type you are editing.

Production checklist

  • The exact template type and real recipient inbox were tested, not only the editor preview.
  • The raw href uses the intended variable: {{ .ConfirmationURL }} or an explicit token-hash URL.
  • {{ .Token }} appears only where an OTP code is really wanted.
  • {{ .RedirectTo }} is not accidentally overridden by a hard-coded {{ .SiteURL }}.
  • The final domain and deep-link path are present in the redirect URL allowlist.
  • Supabase Auth logs and SMTP provider logs agree on where the message stopped.
  • Hourly SMTP limits are not being consumed by tests, invites or retry loops.
  • Link tracking and scanner prefetching are excluded or mitigated for auth links.
  • PKCE links are opened in a browser context that can complete the flow.
  • Signup, invite, magic link, recovery, email-change and reauthentication templates were tested separately.
  • The app still passes the broader lovable deploy production checks for auth, environment variables and public URLs.

When you treat the email template as part of the authentication system, the fix becomes small: correct one variable, allow one redirect, disable one rewrite, or choose the right verification pattern. The dangerous version is the pretty email that almost works.

FAQ

Which variable should supabase email templates use for the login link?

For simple hosted-link flows, {{ .ConfirmationURL }} is the safe default because Supabase assembles the correct confirmation URL. For server-side or PKCE-style confirm pages, build the link explicitly with {{ .TokenHash }}, the correct type parameter and a safe next value. Do not paste raw tokens into links unless the template is specifically designed for OTP entry.

Why does my Supabase email template work in the dashboard but not in production?

The dashboard editor only proves that the template was saved. Production adds real redirect allowlists, SMTP provider rules, rate limits, spam filtering, corporate link scanners, PKCE state and user browsers. Test the complete email in a real inbox and inspect both Supabase Auth logs and the SMTP provider log.

Can I use {{ .SiteURL }} instead of {{ .ConfirmationURL }} in Supabase emails?

Yes, but only when you intentionally construct the correct confirm URL yourself. A hard-coded {{ .SiteURL }} can ignore the redirectTo value passed by the app and send users to the wrong environment. Use {{ .RedirectTo }} where appropriate and make sure the target is allowed in the project’s redirect URL settings.