VibeCPR

← All fixes

Supabase · Auth

Fix Supabase auth redirecting to localhost after deploy

Updated · Applies to: Supabase, Lovable, Bolt, v0, Cursor, Replit, Claude Code, Vercel, Netlify

TL;DR fix: Supabase sends users to your Site URL whenever no redirectTo is given, and the default Site URL is http://localhost:3000. A redirectTo also has to be on the Redirect URLs allow list. Fix: in the dashboard under Authentication, URL Configuration, set Site URL to your live domain, add your live, preview and localhost callback URLs to Redirect URLs, pass redirectTo built from the current site in your sign-in code, and if you pass redirectTo for emails, use {{ .RedirectTo }} instead of {{ .SiteURL }} in your email templates.

Steps

  1. Set the Site URL to your production domain. In the Supabase dashboard open Authentication, then URL Configuration, and change Site URL from http://localhost:3000 to your live URL, such as https://yourapp.com. Supabase uses it whenever your code passes no redirectTo, including confirmation emails and password resets.
  2. Add every place users can land to Redirect URLs. Add your production callback URL, http://localhost:3000/** for local work, and a preview pattern such as https://*-.vercel.app/** or https://**--your-org.netlify.app/** if you use preview deploys.
  3. Pass redirectTo from the current site. In signInWithOAuth, signInWithOtp, signUp and resetPasswordForEmail, pass a redirectTo built from an environment variable or window.location.origin instead of a hard-coded localhost URL.
  4. Update email templates if you use redirectTo. Supabase's email templates default to {{ .SiteURL }}. If your code passes redirectTo for magic links or confirmations, switch the template link to {{ .RedirectTo }} so the email points at the right site.
  5. Check the provider console for Google or GitHub. The Google or GitHub OAuth app must list your Supabase callback, https://<project-ref>.supabase.co/auth/v1/callback, as an authorized redirect URI. Your own domain goes in Supabase's Redirect URLs, not in Google's.
  6. Retest in a private window on the live site. Sign in, request a magic link and a password reset from the deployed site. Every link and redirect should stay on your domain.

Why it works locally and breaks live

Supabase Auth has two settings under Authentication → URL Configuration that AI tools almost never touch:

  • Site URL. Where users go when your code doesn’t say otherwise. It starts as http://localhost:3000, so confirmation emails, password resets and redirect-less sign-ins all point there.
  • Redirect URLs. The allow list. A redirectTo you pass from code is only honored if it matches an entry here.

Locally both are right by accident. After you deploy, users click “Sign in with Google”, magic links or reset emails and land on localhost:3000, which on their machine is nothing at all (“This site can’t be reached”).

The fix

1. Site URL. Set it to your live address, exactly as users type it, for example https://yourapp.com. If you serve both www and the bare domain, pick one, redirect the other to it, and use the one you picked.

2. Redirect URLs. Add each place a login can land:

https://yourapp.com/**
http://localhost:3000/**
https://*-.vercel.app/**            # Vercel previews (from Supabase's docs)
https://**--your-org.netlify.app/** # Netlify previews

In these patterns * stops at . and /, while ** matches across them. Supabase recommends exact paths for production, such as https://yourapp.com/auth/callback, once things work.

3. Pass redirectTo from the current site, not a hard-coded URL:

const siteUrl = import.meta.env.VITE_SITE_URL ?? window.location.origin;

await supabase.auth.signInWithOAuth({
  provider: 'google',
  options: { redirectTo: `${siteUrl}/auth/callback` },
});

await supabase.auth.signInWithOtp({
  email,
  options: { emailRedirectTo: `${siteUrl}/auth/callback` },
});

await supabase.auth.resetPasswordForEmail(email, {
  redirectTo: `${siteUrl}/reset-password`,
});

Search your code for localhost before you deploy. AI tools love leaving redirectTo: 'http://localhost:3000' in a login component.

4. Email templates. Under Authentication → Emails, the templates build links from {{ .SiteURL }}. If you pass redirectTo for email sign-ins, change the link to use {{ .RedirectTo }}, as Supabase’s docs show:

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

5. Google or GitHub console. With Supabase-managed OAuth, the provider redirects to Supabase first, so the provider’s authorized redirect URI is your Supabase callback, https://<project-ref>.supabase.co/auth/v1/callback (or your Supabase custom domain’s callback if you set one). Your own domain doesn’t go there. A redirect_uri_mismatch error from Google means this entry is wrong, not your Supabase settings.

Retest

Open a private window on the live site and try Google sign-in, a magic link, sign-up confirmation and a password reset. Each should end on your domain with a session. If a login still lands on the Site URL instead of the page you asked for, the redirectTo doesn’t match the allow list: check the scheme, www, trailing slashes and path.

Once login works for real users, make sure what they log in to is locked down: check for tables anyone can read with USING (true) and the new-table 42501 error from the Oct 30 grants change.

Prompt for Cursor, Lovable, Bolt or Claude Code

My Supabase auth redirects to localhost after deploy. Find every redirectTo,
emailRedirectTo and hard-coded localhost URL in the code and replace them with a URL
built from a SITE_URL environment variable (falling back to window.location.origin).
Then list exactly what I must set by hand: the Supabase Site URL, the Redirect URLs
allow list (production, localhost and preview patterns), the email template links,
and the authorized redirect URI in the Google/GitHub OAuth console. Don't change auth
settings you can't see; tell me what to check.

When to get help

Get help if users are stuck in a login loop, sessions vanish after the redirect, auth works on one domain but not another (www vs bare, custom domain vs preview), or you want the whole auth setup reviewed before launch.

FAQ

Why does Supabase send users to localhost:3000 after I deploy?

The Site URL in Authentication, URL Configuration defaults to http://localhost:3000, and Supabase uses it as the redirect whenever your code passes no redirectTo. Supabase's docs say to change it to your production URL and call it critical for email confirmations and password resets.

I set redirectTo but users still land on the Site URL. Why?

The redirectTo URL has to match an entry in the Redirect URLs allow list. If it doesn't, Supabase won't send users there. Add the exact URL or a wildcard pattern, keeping in mind that * stops at . and / while ** matches across them.

Why do my magic link and confirmation emails still point at localhost?

The default email templates build links from {{ .SiteURL }}. Fix the Site URL, and if your code passes redirectTo for emails, change the templates to {{ .RedirectTo }}, as Supabase's redirect URL docs recommend.

Do I add my domain to Google Cloud Console?

For Supabase-managed Google sign-in, Google redirects to Supabase first, so the authorized redirect URI in Google is your Supabase callback URL (https://<project-ref>.supabase.co/auth/v1/callback, or your Supabase custom domain if you set one). Your app's own URLs go in Supabase's Redirect URLs list.

How do I make Vercel or Netlify preview deploys work?

Keep Site URL set to production and add a wildcard to Redirect URLs. Supabase's docs suggest https://*-.vercel.app/** for Vercel previews and https://**--my_org.netlify.app/** for Netlify, plus http://localhost:3000/** for local development. Supabase recommends exact paths for production rather than **.

Sources

Related fixes