6. Supabase GoTrue Auth Email Templates
Repository:
Microservices (planovi-microservices)• Rule Prefix:BR-EML• Documented Rules: 4 • Open[TEAM_WHY_NEEDED]Questions: 1
1. Business Purpose & Actors
- Problem Solved: Provides Polish-language, branded HTML email templates consumed by self-hosted Supabase GoTrue (
supabase-authandsupabase-auth-devcontainers on VPS) for all authentication lifecycle emails and security alerts. - Actors:
- Supabase GoTrue Auth Server (VPS): Fetches templates over internal proxy
vps-proxy:8080/email-templates/(perBRANDING_GUIDE.md:332), interpolates Gotext/templatevariables, and sends via SMTP. - Planovi Platform Users: Receive activation, invite, magic-link, password reset, email change, and security notification emails.
- Supabase GoTrue Auth Server (VPS): Fetches templates over internal proxy
2. All Features & End-to-End Flows (Happy Path + Error Paths)
All 9 templates share a 560px centered table layout (<html lang="pl">, <meta name="color-scheme" content="dark">), legacy dark palette (#0F172A background, #1E293B card, #14B8A6/#2DD4BF header/CTA gradient), preheader hidden div, support contact (info@planovi.app), and footer (© Planovi · planovi.app):
| Template File | GoTrue Auth Event | Go Template Variables Used | Action Link / Code Format |
|---|---|---|---|
confirm-signup.html | Email confirmation on signup | {{ .Email }}, {{ .RedirectTo }}, {{ .TokenHash }} | {{ .RedirectTo }}?token_hash={{ .TokenHash }}&type=signup (24h single-use copy) |
invite-user.html | Admin/system user invite | {{ .Email }}, {{ .RedirectTo }}, {{ .TokenHash }} | {{ .RedirectTo }}?token_hash={{ .TokenHash }}&type=invite (24h single-use copy) |
magic-link.html | Passwordless login | {{ .Email }}, {{ .RedirectTo }}, {{ .TokenHash }}, {{ .Token }} | {{ .RedirectTo }}?token_hash={{ .TokenHash }}&type=magiclink + monospace OTP {{ .Token }} (24h copy) |
reset-password.html | Password recovery | {{ .Email }}, {{ .RedirectTo }}, {{ .TokenHash }} | {{ .RedirectTo }}?token_hash={{ .TokenHash }}&type=recovery (24h single-use copy) |
change-email.html | Pending email change confirmation | {{ .Email }}, {{ .NewEmail }}, {{ .RedirectTo }}, {{ .TokenHash }} | {{ .RedirectTo }}?token_hash={{ .TokenHash }}&type=email_change + security link to https://panel.planovi.app |
email-changed.html | Security alert: email changed | {{ .Email }} | CTA & reset link to https://panel.planovi.app |
password-changed.html | Security alert: password changed | {{ .Email }} | CTA & reset link to https://panel.planovi.app |
mfa-removed.html | Security alert: 2FA factor removed | {{ .Email }} | CTA ("Otwórz ustawienia →") & reset link to https://panel.planovi.app |
reauthentication.html | Step-up OTP verification | {{ .Token }} | Monospace OTP box {{ .Token }} (no CTA button) |
3. Hard Business Rules, Validations, Calculations & Edge Cases
BR-EML-01(Directtoken_hashDeep-Links): All 5 actionable link templates (confirm-signup,invite-user,magic-link,reset-password,change-email) construct{{ .RedirectTo }}?token_hash={{ .TokenHash }}&type={type}rather than GoTrue’s{{ .ConfirmationURL }}(a85fa3dd), enabling the Flutter client to callverifyOTPdirectly without email-scanner prefetch invalidation or GoTrue redirect hops.BR-EML-02(Fallback Raw URL Copy):confirm-signup,invite-user,reset-password, andchange-emailinclude a plain clickable fallback URL under"Jeśli przycisk nie działa, skopiuj ten link do przeglądarki:".magic-link.htmlomits the fallback raw URL and instead displays the 6-digit OTP{{ .Token }}.BR-EML-03(Hardcoded Production Panel URL in Security Alerts):change-email.html:23,email-changed.html:20,22,password-changed.html:35,42, andmfa-removed.html:20,22hardcodehttps://panel.planovi.app(not environment-specific for DEV).BR-EML-04(Zone 1 Branding Compliance Gap): All 9 templates belong to Zone 1 (Platform UI) perAGENTS.mdandBRANDING_GUIDE.md:331-342, yet currently still use legacy#0F172A/#1E293B/#14B8A6/#2DD4BFand text header"⚡ Planovi"instead of the#09090B+#32CA42+ PNGlogo-white.pngZone 1 spec.
4. State Machines & Data Lifecycle
Stateless static HTML templates fetched by GoTrue at email send time (no internal state transitions in this repository).
5. Technical Contract (Inputs → Processing → Side Effects)
- Served Path (via
planovi-vps): Internal Nginx proxy mapsdealflow/email-templates/{name}.htmltovps-proxy:8080/email-templates/{name}.html(referenced by GoTrueGOTRUE_MAILER_TEMPLATES_*env vars inplanovi-vps). - Inputs: Go
html/templatecontext fields provided by GoTrue (.Email,.NewEmail,.RedirectTo,.TokenHash,.Token). - Side Effects: None in this repo.
6. Cross-Repository Dependencies
| Caller | Callee | Protocol & Auth | Exact Endpoint / Contract |
|---|---|---|---|
planovi-vps (supabase-auth / supabase-auth-dev GoTrue) | planovi-microservices (dealflow/email-templates/) | Internal HTTP GET (vps-proxy:8080/email-templates/*.html) | Static HTML Go templates |
| Email recipient browser | planovi-flutter-app (panel.planovi.app / {{ .RedirectTo }}) | HTTPS GET deep-link | ?token_hash={hash}&type={signup|invite|magiclink|recovery|email_change} |
7. Why It Works This Way (Decisions, Trade-offs & Workarounds)
- Hosted Inside
dealflow/email-templates/(997a6604): Moved intodealflow/so the existing VPS Nginx proxy servingdealflow/could expose them internally to GoTrue without adding a new deployment pipeline. token_hashLinks (a85fa3dd): Replaced GoTrueConfirmationURLwith{{ .RedirectTo }}?token_hash={{ .TokenHash }}&type=...so links survive corporate email link-scanners and land directly in the Flutter web app’s OTP verification handler.[TEAM_WHY_NEEDED: Is the "24 godziny" expiry text hardcoded in confirm-signup, invite-user, magic-link, reset-password, and change-email templates aligned with the actual GOTRUE_MAILER_OTP_EXP setting on VPS (GoTrue default is 1 hour / 3600s)?]
8. Debugging, Logs & Common Failure Modes
| Symptom / Error Message | Root Cause in Code | How to Verify / Exact Log or Query | Fix |
|---|---|---|---|
Auth link contains double ? (e.g., ?foo=1?token_hash=...) | Templates unconditionally append ?token_hash= to {{ .RedirectTo }} (no check whether RedirectTo already has query params). | Inspect raw email HTML in Mailpit or GoTrue logs. | Ensure callers pass query-free redirectTo URLs, or adjust template/GoTrue config. |
| DEV security alert email sends user to PROD panel | panel.planovi.app is hardcoded in change-email, email-changed, password-changed, mfa-removed. | Inspect href in those 4 templates. | Use {{ .SiteURL }} (if configured per env in GoTrue) instead of hardcoded https://panel.planovi.app. |
| GoTrue falls back to default English email | vps-proxy:8080/email-templates/*.html unreachable or filename mismatch. | Check supabase-auth container logs on VPS (docker logs supabase-auth). | Verify file path in dealflow/email-templates/ and VPS Nginx mount. |