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://supabase.com/docs/guides/auth/redirect-urls (opens in a new tab)

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 redirectTo is specified" and calls it "critical for email confirmations and password resets."
  • redirectTo isn't on the allow list. Supabase's KB says that "you must set the exact URL in the shown Redirect URL's setting" for redirectTo to work.
  • Email templates hard-code the Site URL. A template link built from {{ .SiteURL }} points at the Site URL, not the redirectTo you passed.

How to fix it, step by step

  1. In the Supabase dashboard, open Authentication → URL Configuration.
  2. Change Site URL from http://localhost:3000 to your production URL, such as https://yourapp.com.
  3. Under Redirect URLs, add the exact production callback URL(s) your code uses. Supabase recommends exact paths in production and wildcards for previews.
  4. 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)
  5. If your code passes redirectTo, build it from your production URL. Supabase suggests a NEXT_PUBLIC_SITE_URL variable for production, falling back to Vercel's NEXT_PUBLIC_VERCEL_URL. Redeploy after changing it, since Next.js inlines NEXT_PUBLIC_ values at build time.
  6. If your email templates are customized and you use redirectTo, replace {{ .SiteURL }} with {{ .RedirectTo }} in the template links.
  7. 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 redirectTo fails silently. Supabase Auth's source checks the requested redirectTo, then the browser's Referer header, 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 match http://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

  1. https://supabase.com/docs/guides/auth/redirect-urls (opens in a new tab): Site URL default and "critical" note, allow list, wildcard rules, Vercel/Netlify patterns, NEXT_PUBLIC_SITE_URL, email templates, error fragments, self-hosted config
  2. https://supabase.com/docs/guides/troubleshooting/why-am-i-being-redirected-to-the-wrong-url-when-using-auth-redirectto-option-_vqIeO (opens in a new tab): exact URL must be on the allow list
  3. https://github.com/supabase/auth/blob/master/internal/utilities/request.go (opens in a new tab): GetReferrer falls back to config.SiteURL; same-host rule
  4. https://nextjs.org/docs/app/guides/environment-variables (opens in a new tab): NEXT_PUBLIC_ values inlined at build time

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.