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
- 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.
- 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.
- 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.
- 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.
- 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.
- 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
redirectToyou 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.
Want us to look at your app?
VibeCPR Rescue Reports are launching soon: we scan your repo and live app, and a human verifies every critical finding. Join the waitlist for early access and founder pricing. You'll also get Patch Notes, our weekly fixes newsletter.
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
- AI agent pushed API keys to GitHub? git commit --no-verify skipped your pre-commit hook
- Fix a surprise AI API bill: rate limits and spend caps
- Your app is public to anyone with the link: a share link is not a login
- Triage Bolt's "RLS Policy Always True" warning: when it's fine and how to fix it
- Fix secrets leaked via Claude Code .claude/settings.local.json
- Fix "Your Cloud Firestore database has insecure rules" (Firebase email)
- Login lockout keyed only on email? Rate-limit by IP and account without locking users out
- Fix Lovable "Invalid API key" after rotating Supabase keys (anon, publishable, secret)
- Lovable won't publish because of security findings? What each finding means and how to fix it
- "Sign in with Google" lets anyone in: restrict who can use your app (allowlist, domain check, RLS)
- Fix Stripe sk_live keys left in MCP or agent config
- Fix Stripe webhook "No signatures found matching the expected signature for payload"
- Fix Supabase Edge Function "blocked by CORS policy" (preflight)
- Fix Supabase "infinite recursion detected in policy for relation" (42P17) in RLS
- Form says success but no row in Supabase (or Stripe webhook returns 200 but writes nothing)
- Fix "new row violates row-level security policy for table" (Supabase)
- Supabase only returns 1,000 rows? Fix the silent max rows limit in Lovable and Bolt apps
- Fix Supabase "permission denied for table" (42501) on new tables after Oct 30, 2026
- Fix a Supabase public Storage bucket that lets anyone list or download your files
- Supabase Realtime leaking rows or not receiving changes: fix RLS and the publication
- Supabase RLS not working on the server? Your API uses the service_role or secret key
- Fix Supabase RLS policy USING (true) that makes a table publicly readable
- Your app's rules only live in the frontend: move them into Supabase
- Fix a Supabase SECURITY DEFINER function anyone can call through /rest/v1/rpc
- Fix Supabase .single() "JSON object requested, multiple (or no) rows returned" (PGRST116)
- Stop Supabase users from upgrading their own plan or making themselves admin
- Fix a Supabase view that bypasses RLS: security_invoker and revoking anon write grants
- Fix "404: NOT_FOUND" on refresh in a React/Vite app on Vercel (vercel.json rewrite)
- Fix "Module not found: Can't resolve" on Vercel (works locally)
- Is my Vite dev server exposed? Check --host / server.host and patch the RCE (GHSA-p4f5-76q4-ffq7)