fix(auth): send magic links through Mailgun in prod, fail clearly without a mailer #25
No reviewers
Labels
No labels
bug
docs
duplicate
enhancement
help wanted
invalid
nice-to-have
pre-1.0
question
security
wontfix
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
jfro/lamplighter!25
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/10-prod-mailer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #10 (gap audit F1).
In prod,
config/prod.exskeptSwoosh.Adapters.Localwith its storage turned off, so registering or "Log in with email" exited with:noproc, and without OIDC nobody could log in.What changes
config/runtime.exs(prod): Swoosh's Mailgun adapter over the existing Req API client whenMAILGUN_API_KEYandMAILGUN_DOMAINare set (Mailgun per Jeremy, no new dependency).MAILGUN_BASE_URLfor EU domains,MAIL_FROMasaddrorName <addr>(defaultlamplighter@<MAILGUN_DOMAIN>). This is the mailer #5's email channel can reuse.Lamplighter.Mailer.Unconfigured, which returns{:error, :mailer_not_configured}instead of crashing.UserNotifierusesMailer.from/0(wascontact@example.com) and logs failed sends with subject, recipient domain, adapter, duration and reason./dev/mailboxbanner only shows withdev_routes.Tests:
test/lamplighter/mailer_test.exs(7): readsruntime.exsfor:prodwith and without the Mailgun vars, MAIL_FROM parsing, the unconfigured send returns an error and logs it, and the login and registration pages without a mailer. 6 of 7 fail on main.mix precommit: 631 pass.Not tried against a live Mailgun account.
Screenshots (no mailer configured), desktop and 390px:




Review (Nye) at
38025f8: approve.Checked against Swoosh 1.28.1's Mailgun adapter and Swoosh.ApiClient.Req:
mix precommitpasses (632 tests incl. mailer_test.exs). CI green.Note, not blocking: Swoosh's Mailgun adapter declares
required_deps: [multipart: Multipart, ...], andLamplighter.Mailerhas@on_load :validate_dependency. If the Mailer module is first loaded after the adapter is Mailgun, the on_load aborts and the module won't load (seen in test, where modules load lazily). In a release, modules load at boot before runtime.exs runs (checked with a scratch release: on_load saw the build-time adapter), sobin/serveris fine.bin/... evalpaths that send mail, and any attachment, would fail. Adding{:multipart, "~> 0.4"}would make this robust; fine as a follow-up.