Supabase login redirects to localhost:3000 after deploy
On this page
Short answer
Supabase falls back to your Site URL when the redirectTo your code passes isn't on the Redirect URLs allow list, or no redirectTo is passed at all. Supabase's docs tell you to change the Site URL from http://localhost:3000 before going live. Change it to your live address in Authentication → URL Configuration, add your live domain to Redirect URLs, and test again.
Find a fix pack
Checklists and prompts for Supabase security, Stripe payments and deploys. Each pack is $24, or $49 for all three.
The exact error you'll see
There's no error message. After sign-up confirmation, a magic link, a password reset or OAuth sign-in, the browser's address bar lands on:
http://localhost:3000
Source: https:/
On a live site, that address only works on the developer's own machine. When authentication itself fails, Supabase still redirects and puts error_code and error_description in the URL fragment, so check the address bar for those.
Applies to
- Hosted Supabase Auth: email confirmation, magic links and OTP, password reset, OAuth providers such as Google or GitHub
- Apps built with Lovable (own Supabase project), Bolt, Cursor, v0, deployed to Vercel, Netlify or a custom domain
- Settings: Site URL and Redirect URLs on the URL Configuration page; email templates using
{{ .SiteURL }} - Self-hosted or local projects use the config file (
auth.additional_redirect_urls) instead
Why it happens
- Site URL still points at localhost. Supabase says the Site URL "defines the default redirect URL when no
redirectTois specified" and calls it "critical for email confirmations and password resets." redirectToisn't on the allow list. Supabase's KB says that "you must set the exact URL in the shown Redirect URL's setting" forredirectToto work.- Email templates hard-code the Site URL. A template link built from
{{ .SiteURL }}points at the Site URL, not theredirectToyou passed.
How to fix it, step by step
- In the Supabase dashboard, open Authentication → URL Configuration.
- Change Site URL from
http://localhost:3000to your production URL, such ashttps://yourapp.com. - Under Redirect URLs, add the exact production callback URL(s) your code uses. Supabase recommends exact paths in production and wildcards for previews.
- For previews, Supabase documents these patterns:
- Vercel:
https://*-<team-or-account-slug>.vercel.app/** - Netlify:
https://**--my_org.netlify.app/** - Local:
http://localhost:3000/**(keep only while you develop locally)
- Vercel:
- If your code passes
redirectTo, build it from your production URL. Supabase suggests aNEXT_PUBLIC_SITE_URLvariable for production, falling back to Vercel'sNEXT_PUBLIC_VERCEL_URL. Redeploy after changing it, since Next.js inlinesNEXT_PUBLIC_values at build time. - If your email templates are customized and you use
redirectTo, replace{{ .SiteURL }}with{{ .RedirectTo }}in the template links. - These are Supabase dashboard settings, not code, so an AI builder that only edits your code can't change them. Do steps 1–4 yourself.
What the docs don't spell out
- A rejected
redirectTofails silently. Supabase Auth's source checks the requestedredirectTo, then the browser'sRefererheader, and returns the Site URL if neither is allowed. You get no error, just a redirect to the Site URL. (supabase/auth source (opens in a new tab)) - Same host as Site URL is allowed automatically. The same source allows any URL whose scheme, host and port match the Site URL. With Site URL on your real domain, its own paths work without separate entries. Other domains, including previews, still need allow-list entries. (supabase/auth source (opens in a new tab))
*doesn't cross dots or slashes. Supabase treats.and/as separators:http://localhost:3000/*won't matchhttp://localhost:3000/foo/bar, but/**will. (Supabase docs (opens in a new tab))
How to check it worked
- Sign up with a fresh email on the live site. The confirmation link should open your domain.
- Request a password reset. The link should point at your domain.
- Try OAuth sign-in. After returning, the address bar should show your domain with no
error_description.
Sources
- https:/
/ : Site URL default and "critical" note, allow list, wildcard rules, Vercel/Netlify patterns,supabase. com/ docs/ guides/ auth/ redirect- urls (opens in a new tab) NEXT_PUBLIC_SITE_URL, email templates, error fragments, self-hosted config - https:/
/ : exact URL must be on the allow listsupabase. com/ docs/ guides/ troubleshooting/ why- am- i- being- redirected- to- the- wrong- url- when- using- auth- redirectto- option- _ vqIeO (opens in a new tab) - https:/
/ :github. com/ supabase/ auth/ blob/ master/ internal/ utilities/ request. go (opens in a new tab) GetReferrerfalls back toconfig.SiteURL; same-host rule - https:/
/ :nextjs. org/ docs/ app/ guides/ environment- variables (opens in a new tab) NEXT_PUBLIC_values inlined at build time
Related fixes
Tool to consider: Supabase.
Find a fix pack
Checklists and prompts for Supabase security, Stripe payments and deploys. Each pack is $24, or $49 for all three.