Supabase login redirects to localhost in production: the fix
After login or email confirmation your live app sends users to localhost:3000. The cause is Supabase's Site URL setting. Here is the fix, step by step.
4 min readsupabase, authentication, error fix, deployment
Short answer: Supabase falls back to its Site URL setting when your code does not say where to send the user, and that setting starts out as http://localhost:3000. Change the Site URL to your real address, add your live addresses to the Redirect URLs list, and pass the address in your code. Then test again on the live domain.
You see this when a user confirms their email, resets a password or signs in with Google or GitHub on your live site and lands on localhost, where the page does not exist.
Why it happens
When a user finishes an authentication step, Supabase has to send them back to your app. It chooses the address like this:
- If your code passes a
redirectTo(oremailRedirectTo) value, and it is on the allowed list, Supabase uses it. - If not, it uses the Site URL from your project settings.
AI tools and quick starts usually leave the Site URL at its default, because everything works on your own computer. Nothing looks wrong until real users arrive.
Fix 1: change the Site URL
- Open your Supabase project.
- Go to Authentication, then URL Configuration.
- Set Site URL to your live address, for example
https://yourdomain.com, with no trailing slash. - Save.
This alone fixes most confirmation emails, because the link in the email is built from this value.
Fix 2: add your live addresses to the allow list
In the same screen, Redirect URLs is the list of addresses Supabase is willing to send people to. If your code asks for an address that is not on the list, Supabase ignores it and falls back to the Site URL.
Add:
https://yourdomain.com/**https://www.yourdomain.com/**if you usewww- your preview or staging address if you have one
Wildcards are handy for previews. For production, an exact path such as https://yourdomain.com/auth/callback is safer, because it limits where tokens can be sent.
Fix 3: pass the address from your code
Do not hard-code localhost. Use the address the app is running on:
await supabase.auth.signUp({
email,
password,
options: {
emailRedirectTo: `${window.location.origin}/welcome`,
},
});
await supabase.auth.signInWithOAuth({
provider: "google",
options: {
redirectTo: `${window.location.origin}/auth/callback`,
},
});
window.location.origin is the address in the browser, so it is right on your computer, on previews and in production. On the server you can read the address from one setting, such as NEXT_PUBLIC_SITE_URL, but make sure that setting exists on your host, not just on your laptop.
Fix 4: check your social login providers
If only Google or GitHub login is affected, also check the provider's own settings. Each provider has an authorised redirect address that should point to your Supabase project's callback address, which Supabase shows in its provider settings. That one is separate from your app's address.
If it still goes to localhost
- Old emails. A confirmation email sent before you changed the setting still carries the old link. Send a new one.
- Hard-coded address. Search your code for
localhost,127.0.0.1and any preview address. - Cached build. If the address comes from an environment variable, redeploy so the new value is built in.
- Mobile only. Check the phone's browser separately. Reports exist of production working on desktop and still redirecting on mobile when a Redirect URLs entry was missing.
- Custom email templates. If you edited the email template, make sure the link uses the built-in value for the confirmation address and not a typed address.
Ask your AI tool
"After login and email confirmation our live app redirects to localhost. Remove every hard-coded localhost URL, pass emailRedirectTo and redirectTo using window.location.origin, and list the exact Site URL and Redirect URLs I must set in the Supabase dashboard for https://yourdomain.com."
FAQ
What is the Supabase Site URL?
It is the default address Supabase redirects to after authentication when your code does not pass one.
Do I need to add my domain to Redirect URLs as well?
Yes, if your code passes a redirect address. Addresses not on the list are ignored.
Why does it work on the preview address and fail on my domain?
The preview address may be on the list while your domain is not, or the Site URL still points at localhost.
Is a wildcard redirect safe?
For previews, yes. In production use exact paths where you can.
Moving from preview to live?
This is one of several settings that quietly differ between test and live, and our audit checks them before launch. Send us a link.