Skip to content
📦 ARCHIVED SNAPSHOT (v1.0) You are viewing historical business logic and documentation for Microservices (PHP) v1.0 (frozen on 2026-11-23, commit 96144c89). Switch to Latest →

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-auth and supabase-auth-dev containers 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/ (per BRANDING_GUIDE.md:332), interpolates Go text/template variables, and sends via SMTP.
    • Planovi Platform Users: Receive activation, invite, magic-link, password reset, email change, and security notification emails.

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 FileGoTrue Auth EventGo Template Variables UsedAction Link / Code Format
confirm-signup.htmlEmail confirmation on signup{{ .Email }}, {{ .RedirectTo }}, {{ .TokenHash }}{{ .RedirectTo }}?token_hash={{ .TokenHash }}&type=signup (24h single-use copy)
invite-user.htmlAdmin/system user invite{{ .Email }}, {{ .RedirectTo }}, {{ .TokenHash }}{{ .RedirectTo }}?token_hash={{ .TokenHash }}&type=invite (24h single-use copy)
magic-link.htmlPasswordless login{{ .Email }}, {{ .RedirectTo }}, {{ .TokenHash }}, {{ .Token }}{{ .RedirectTo }}?token_hash={{ .TokenHash }}&type=magiclink + monospace OTP {{ .Token }} (24h copy)
reset-password.htmlPassword recovery{{ .Email }}, {{ .RedirectTo }}, {{ .TokenHash }}{{ .RedirectTo }}?token_hash={{ .TokenHash }}&type=recovery (24h single-use copy)
change-email.htmlPending email change confirmation{{ .Email }}, {{ .NewEmail }}, {{ .RedirectTo }}, {{ .TokenHash }}{{ .RedirectTo }}?token_hash={{ .TokenHash }}&type=email_change + security link to https://panel.planovi.app
email-changed.htmlSecurity alert: email changed{{ .Email }}CTA & reset link to https://panel.planovi.app
password-changed.htmlSecurity alert: password changed{{ .Email }}CTA & reset link to https://panel.planovi.app
mfa-removed.htmlSecurity alert: 2FA factor removed{{ .Email }}CTA ("Otwórz ustawienia →") & reset link to https://panel.planovi.app
reauthentication.htmlStep-up OTP verification{{ .Token }}Monospace OTP box {{ .Token }} (no CTA button)

3. Hard Business Rules, Validations, Calculations & Edge Cases

  • BR-EML-01 (Direct token_hash Deep-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 call verifyOTP directly without email-scanner prefetch invalidation or GoTrue redirect hops.
  • BR-EML-02 (Fallback Raw URL Copy): confirm-signup, invite-user, reset-password, and change-email include a plain clickable fallback URL under "Jeśli przycisk nie działa, skopiuj ten link do przeglądarki:". magic-link.html omits 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, and mfa-removed.html:20,22 hardcode https://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) per AGENTS.md and BRANDING_GUIDE.md:331-342, yet currently still use legacy #0F172A/#1E293B/#14B8A6/#2DD4BF and text header "⚡ Planovi" instead of the #09090B + #32CA42 + PNG logo-white.png Zone 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 maps dealflow/email-templates/{name}.html to vps-proxy:8080/email-templates/{name}.html (referenced by GoTrue GOTRUE_MAILER_TEMPLATES_* env vars in planovi-vps).
  • Inputs: Go html/template context fields provided by GoTrue (.Email, .NewEmail, .RedirectTo, .TokenHash, .Token).
  • Side Effects: None in this repo.

6. Cross-Repository Dependencies

CallerCalleeProtocol & AuthExact 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 browserplanovi-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 into dealflow/ so the existing VPS Nginx proxy serving dealflow/ could expose them internally to GoTrue without adding a new deployment pipeline.
  • token_hash Links (a85fa3dd): Replaced GoTrue ConfirmationURL with {{ .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 MessageRoot Cause in CodeHow to Verify / Exact Log or QueryFix
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 panelpanel.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 emailvps-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.