Guide

Supabase auth redirects to localhost after deploy: how to fix it

Last checked 18 Nov 2026 · 9 min read · by Ship Weekend

Short answer: in the Supabase Dashboard, open Authentication → URL Configuration. Change the Site URL from http://localhost:3000 to your live URL, and add every URL your code passes as redirectTo / emailRedirectTo to the Redirect URLs allow-list. Supabase uses the Site URL whenever no redirect is given,¹ and when the URL you pass isn't on the allow-list it falls back to the Site URL too.²⁶ So a project still set to localhost sends confirmation emails, magic links, password resets and OAuth logins straight back to localhost:3000.

If those two settings are already right, work down the rest of this page: the redirect your code sends, the OAuth provider's callback, your email templates, a new custom domain, and links opened in a different browser.

Why it happens

Supabase projects start with http://localhost:3000 as the Site URL. Bolt's docs say the same for Bolt projects.² Locally that's correct, so nothing looks wrong until the app is live and the first real user clicks a confirmation link.

Every Supabase sign-in that leaves your app and comes back (email confirmation, magic link, password reset, Google or GitHub) ends with Supabase redirecting the browser to one URL. It picks:

Fix 1: Set the Site URL to your live URL

Dashboard → Authentication → URL Configuration → Site URL. Set it to the address real users use, e.g. https://yourapp.com. Supabase's docs call this setting "critical for email confirmations and password resets".¹

Use your primary domain here, not a preview URL. If you use both www.yourapp.com and yourapp.com, pick the one your site redirects to.

Fix 2: Add your URLs to the Redirect URLs allow-list

Same page, Redirect URLs. Supabase's support answer for "why are redirects going to localhost instead of the production site URL?" is that the exact URL you pass in redirectTo must be on this list.⁶ Scheme, host and path all matter: http:// vs https://, www vs no www, and /auth/callback vs /.

Wildcards are supported. . and / count as separators:¹

Pattern Matches
* any characters except . and /
** any characters, including . and /
? one character except . and /

So http://localhost:3000/* matches /foo but not /foo/bar or /foo/ (trailing slash), while http://localhost:3000/** matches all three.¹

A typical setup:

https://yourapp.com/auth/callback          # exact production path(s)
http://localhost:3000/**                   # local development
https://*-<team-or-account-slug>.vercel.app/**   # Vercel previews
https://**--my_org.netlify.app/**          # Netlify deploy previews

The Vercel and Netlify lines are the patterns from Supabase's docs; replace the slug with your own Vercel team or account slug, and my_org with your Netlify site name.¹ Supabase recommends the exact path for production and keeping ** for local development and previews.¹

If you run Supabase locally with the CLI, supabase/config.toml holds the local Site URL and redirect list.¹ Editing it doesn't change your hosted project.

Fix 3: Pass the right redirect from your code

AI-generated auth code often hard-codes http://localhost:3000, or passes nothing and relies on the Site URL. Search your code for localhost and for these four calls, which all take a redirect option:³

// sign-up confirmation email
await supabase.auth.signUp({
  email, password,
  options: { emailRedirectTo: `${window.location.origin}/auth/callback` },
})

// magic link
await supabase.auth.signInWithOtp({
  email,
  options: { emailRedirectTo: `${window.location.origin}/auth/callback` },
})

// Google, GitHub and other OAuth providers
await supabase.auth.signInWithOAuth({
  provider: 'google',
  options: { redirectTo: `${window.location.origin}/auth/callback` },
})

// password reset
await supabase.auth.resetPasswordForEmail(email, {
  redirectTo: `${window.location.origin}/update-password`,
})

window.location.origin follows whichever domain the user is on, so the same build works on localhost, a preview and production. That only helps if each of those origins is on the allow-list from Fix 2.

For server-rendered apps, or if you want one fixed value, read it from an environment variable instead. Supabase's docs show a getURL() helper that uses NEXT_PUBLIC_SITE_URL, falls back to Vercel's NEXT_PUBLIC_VERCEL_URL, then to localhost, and adds https:// and a trailing slash.¹ In a Vite app (most Lovable and Bolt projects) the equivalent would be a VITE_SITE_URL variable set in your host's environment settings. Rebuild and redeploy after you change it, because Vite bakes variables in at build time.

Watch for doubled slashes when you join strings: https://yourapp.com//auth/callback won't match https://yourapp.com/auth/callback.

Fix 4: OAuth (Google, GitHub) callback URLs

Social login has two hops and two allow-lists, and people often mix them up:

  1. Provider → Supabase. In Google Cloud Console (Authorized redirect URIs) or your GitHub OAuth app (Authorization callback URL), the redirect must be your Supabase callback, https://<project-ref>.supabase.co/auth/v1/callback, not your app's URL. Copy it from Dashboard → Authentication → Sign In / Providers → the provider.⁴
  2. Supabase → your app. That's the redirectTo from Fix 3, checked against the Redirect URLs list from Fix 2.

For Google, Supabase also says to add your app's URL under Authorized JavaScript origins. It says to remove the http://localhost entries you used in development once the app is in production.⁴ Google's redirect_uri_mismatch error means hop 1 is wrong. Landing on localhost after a successful Google screen usually means hop 2 is.

If you set the project up with the Supabase CLI, the local callback is http://localhost:54321/auth/v1/callback.⁴ That's a common leftover in a GitHub OAuth app made during development.

Fix 5: Email templates that use {{ .SiteURL }}

The default templates link to {{ .ConfirmationURL }}, which already carries your redirect_to.⁵ But if you, a tutorial or your AI tool customised a template to build its own link, check which variable it starts with:

Supabase's docs say that when you use redirectTo you may need to switch the template from {{ .SiteURL }} to {{ .RedirectTo }}, for example:¹

<a href="{{ .RedirectTo }}/auth/confirm?token_hash={{ .TokenHash }}&type=email">Confirm email address</a>

Templates live under Authentication → Email Templates in the dashboard. Check Confirm sign up, Magic link, Reset password, Invite user and Change email address.⁵

Fix 6: You moved to a custom domain (Lovable, Bolt)

A new domain means a new origin, and it has to be on the allow-list too.

After switching domains, also update the Site URL (Fix 1) if the custom domain is now your main address.

If the link doesn't go to localhost but sign-in still fails with an error about the code or the code verifier, look at where the link was opened. With the PKCE flow (the default for server-side auth helpers), the browser that started sign-in stores a code verifier. The code in the link can only be exchanged on that same browser and device. It's valid for 5 minutes and works once.⁷ Requesting a magic link on a laptop and opening it on a phone, or tapping it inside an email app's built-in browser, breaks that.

Ways round it:

Starting two sign-ins at once in the same browser, say in two tabs, can also overwrite the stored verifier.⁷ Supabase notes another cause of "Token has expired or is invalid": email security scanners such as Microsoft Defender's Safe Links open the link before the user does. The OTP code avoids that too.⁵

Checklist

How to test it (10 minutes)

Use a private window, and an email address that has never signed up.

  1. Sign up on the live site. Open the confirmation email and hover over the link: with the default template, the redirect_to= part should be your live domain. Click it and confirm you land signed in on the live site.
  2. Magic link (if you use it): request one and open it in the same browser. Then request another and open it on your phone, so you know what users see when they do that.
  3. Password reset: request a reset and check that the link opens your update-password page on the live domain.
  4. Google / GitHub: sign in from the live site. You should go to the provider, then back to the live site, never to localhost.
  5. Preview deploy (if you allow-listed one): repeat step 4 on a preview URL. It should return to that preview, not production.
  6. If anything lands on the wrong URL, look at the address bar. Supabase still redirects on failure and puts error_code and error_description in the URL fragment, which usually names the problem.¹

FAQ

Why does Supabase redirect to localhost:3000 after I deployed? Your project's Site URL is still http://localhost:3000, or the URL your code passes as redirectTo isn't on the Redirect URLs allow-list, so Supabase falls back to the Site URL. Fix both under Authentication → URL Configuration.

Do I put my app URL or the Supabase URL in Google Cloud Console? Under Authorized redirect URIs, the Supabase callback: https://<project-ref>.supabase.co/auth/v1/callback. Your app's URL goes under Authorized JavaScript origins and in Supabase's Redirect URLs list.

Can I use wildcards in Supabase redirect URLs? Yes. * matches anything except . and /, and ** matches anything. Supabase suggests wildcards for local development and preview deploys, and exact paths for production.

My confirmation email still links to localhost after I fixed the Site URL. Why? Check for a custom email template that builds its link from a hard-coded URL, and for code passing a localhost emailRedirectTo. Emails already sent keep their old links, so request a new one after the fix.


Want a second pair of eyes before launch? The free Quick Check looks at your live URL for leaked keys, exposed files, HTTPS and SEO basics in about 20 seconds. The $49 Launch Check goes further and gives you a plain-English fix list with copy-paste prompts for Lovable, Bolt or Cursor. Neither one signs in to your app, so test your auth flows with the steps above. If you're also checking your database, see the Supabase RLS launch checklist and the 5-minute leak check.

Sources

  1. Supabase docs, Redirect URLs (Site URL, allow-list, wildcards, Vercel/Netlify patterns, getURL helper, email templates with redirectTo, error fragments): https://supabase.com/docs/guides/auth/redirect-urls
  2. Bolt docs, Database authentication settings (Site URL defaults to localhost:3000; Supabase falls back to the Site URL when a URL isn't on the allow-list): https://support.bolt.new/bolt-cloud/database/authentication
  3. Supabase JavaScript reference, signUp, signInWithOtp, signInWithOAuth, resetPasswordForEmail: https://supabase.com/docs/reference/javascript/auth-signup
  4. Supabase docs, Login with GitHub and Login with Google (callback URL, authorized origins and redirect URIs): https://supabase.com/docs/guides/auth/social-login/auth-github · https://supabase.com/docs/guides/auth/social-login/auth-google
  5. Supabase docs, Email Templates ({{ .SiteURL }}, {{ .RedirectTo }}, {{ .Token }}, email prefetching): https://supabase.com/docs/guides/auth/auth-email-templates
  6. Supabase troubleshooting, Why am I being redirected to the wrong url when using auth redirectTo option?: https://supabase.com/kb/troubleshooting/why-am-i-being-redirected-to-the-wrong-url-when-using-auth-redirectto-option-_vqIeO
  7. Supabase docs, PKCE flow (same browser and device, 5-minute single-use code, overlapping flows): https://supabase.com/docs/guides/auth/sessions/pkce-flow
  8. Lovable docs, Custom domain (why sign-in fails on a custom domain): https://docs.lovable.dev/features/custom-domain