Magic Links Failed With 403 "Invalid origin": My Landing Page Was Posting to the Wrong App
The sign-in form worked locally and failed in production with a 403. The auth library was doing its job: the request came from an origin it didn't trust.
Symptom
Requesting a magic link on the live site returned 403 "Invalid origin". Worse, the form sent people to "check your email" either way, so the failure was invisible to anyone signing in.
Root cause
At the time, www.decouplex.com and the apex were served by the Finance project, so the sign-in form could be submitted from www. The auth server's trusted origin was finance.decouplex.com only. Better Auth checks the Origin header on state-changing requests (CSRF protection), saw www, and refused.
The check was right. The deployment layout was wrong.
Fix
- **Moved
wwwand the apex to the landing-site project.** The only origin that ever submits to Finance's auth is now Finance itself. The landing page links to sign-in; it doesn't host the form. - The form now reports failures. A non-2xx response shows an error instead of always redirecting to "check your email".
I didn't add www to the trusted origins. That would have "worked" and widened the CSRF surface for no reason.
Lessons
- A CSRF error is usually telling you the truth. Fix where the request comes from before loosening what's trusted.
- Never paint success over a failed request. The silent redirect turned a two-minute bug into a mystery.
- Domain layout is security design. Which deployment serves which hostname decides which origins exist.
Sources: DecoupleX build log, "live (end of day)" (9 Nov 2026)