Debugging StoryThe three-letter bug
During testing, magic links kept dumping signed-in users onto the homepage with an unused auth code sitting in the URL, which is the auth equivalent of being handed a key that opens nothing. The flow crosses three systems (the email template, the auth provider's redirect allowlist, and my callback route), so there were plenty of places to look, and the actual culprit was hiding in none of them.
The root cause was a chain: the hosting config was silently redirecting the apex domain to www (backwards from what anyone intended, and invisible because Chrome hides the www), www was not on the auth allowlist, so the redirect fell back to the site URL, and even when the page did load, the PKCE verifier cookie had been set on the other origin, so the code exchange failed anyway. Three separate systems, all misbehaving in the same direction, all because of three letters.
The fix: canonicalize the domain first (apex serves the site, www permanently redirects to apex), then align the auth site URL and allowlist to the one true origin. The lesson I keep: when auth redirects misbehave, audit your origins before you audit your code. Mixed www and apex origins silently break anything that is per-origin, which is cookies, which is PKCE, which is your login.