Login emails pointing to localhost? Fix your auth redirect URLs
Signup works perfectly in the builder's preview. Then a real visitor signs up on your live domain, opens the confirmation email, clicks the link, and lands on http://localhost:3000, an old preview address, or an error page. Password-reset and magic-link emails do the same thing.
The symptom
- Confirmation, magic-link or password-reset links open
localhost, a.lovable.app,.bolt.new,.replit.devor.vercel.appaddress instead of your domain. - The link opens your site but shows an error such as "redirect URL not allowed", or quietly drops the visitor on the homepage, logged out.
Why it happens
Auth providers such as Supabase don't trust any address they haven't been told about. They keep two settings for that:
- Site URL. The default address used in auth emails and the fallback when no other redirect is given or allowed.
- Redirect URLs. An allow list of addresses the provider may send people back to after they click a link or finish signing in with Google, GitHub and so on.
When the project was created, the Site URL was usually set to localhost or the preview address, because that was the only address that existed. Moving to a custom domain doesn't update it. If your code asks to redirect to an address that isn't on the allow list, the provider ignores it and falls back to the Site URL, which is the old one.
Some apps also hard-code the redirect in the code, for example an emailRedirectTo or redirectTo value pointing at the preview address. That breaks the live flow even when the dashboard settings are right.
Step-by-step diagnosis
- Reproduce it as a stranger. Open your live site in a private window and sign up with a fresh email address you can read. Don't use an account you created in preview.
- Read the link before you click it. In the email, copy the link address. Look for a
redirect_to=parameter. Its value is where the visitor will land after the token is checked. - Compare it with your live address character by character.
https://yoursite.com,https://www.yoursite.comandhttp://yoursite.comare all different. - Check the dashboard. In Supabase, open Authentication, then URL Configuration, and note the Site URL and every Redirect URL listed.
- Search the code. Look for
emailRedirectTo,redirectTo,localhostand your preview domain. A hard-coded address there wins over everything else, as long as it's on the allow list. - Repeat for password reset and any social login. They often use different code paths.
Fixes per builder and host
Supabase (behind most Lovable, Bolt and many v0 apps)
- Set Site URL to your main live address, with
https. - Add every address you really use to Redirect URLs: the custom domain, the
wwwversion if it's reachable, and the preview address if you still test there. Supabase accepts wildcards, so a pattern can cover preview deploys, but keep patterns as narrow as you can.
Lovable
Ask Lovable: "My live domain is https://yoursite.com. Find every auth redirect in the code, build it from window.location.origin instead of a fixed address, and tell me which Site URL and Redirect URLs I need in the auth settings." Then update those settings and republish.
Bolt
Bolt apps on Supabase need the same dashboard change. Also check that any site URL environment variable has your live domain in production.
Replit
If the app uses Supabase or another hosted auth service, update its allowed URLs to the deployment's custom domain, not the .replit.dev workspace address. If you wrote your own email links, build them from a production URL setting rather than the request host.
v0 and Vercel
Vercel gives each preview deploy its own URL. Put your production domain in the auth provider's Site URL, and only add a preview pattern to the redirect list if you need to test sign-in on previews.
Cursor
Ask Cursor to "find every place that builds an auth redirect or email link and list the address each one uses". Replace fixed addresses with a single setting.
How to verify
- Sign up again on the live site with a new email in a private window. Click the link and confirm you land on your live domain, logged in.
- Request a password reset and finish it. Then try each social login.
Prevention
- Never hard-code a domain in auth calls. Build redirects from the current origin or one production setting.
- Add "update auth URLs" to your checklist whenever you add or change a domain, before switching DNS.
- After each deploy that touches auth, run one real signup on the live site.
A login test that passed in preview proves the preview works. Only a fresh signup on the live domain proves your visitors can get in.
FlowCanary's free check opens your live site as a new visitor would and flags broken pages, console errors and missing signup pages, with a fix prompt for your builder. It never signs up or logs in, so test the email links yourself as above.
