Supabase login or magic link redirects to localhost:3000 (fixed)
Your app is live, but a confirmation email, magic link, password reset or Google login sends people to http://localhost:3000 and they see "This site can't be reached". The app is fine. Supabase is following its own settings: when it doesn't accept the address your app asked for, it falls back to the project's Site URL, and the Site URL of a new project starts as http://localhost:3000. Supabase's Redirect URLs docs describe the setup.
Why it happens
- The Site URL was never changed. It is the default place Supabase sends users when your code passes no
redirectTooremailRedirectTo. Lovable, Bolt and Cursor rarely change it for you. - Your redirect isn't on the allow list. If your code asks for
https://myapp.com/welcomebut that address isn't under Redirect URLs, Supabase ignores it and uses the Site URL instead. - The code hardcodes localhost. AI builders sometimes write
emailRedirectTo: 'http://localhost:3000'during development and it ships to production. - Old emails. Links in emails sent before you changed the settings still point to the old address. Send a fresh one when testing.
The fix (two minutes)
- In Supabase, open Authentication → URL Configuration.
- Set Site URL to your live address, for example
https://myapp.com. - Under Redirect URLs, add the exact pages you redirect to in production, such as
https://myapp.com/auth/callback. Keephttp://localhost:3000/**only if you still develop locally. - In your code, build the redirect from the current address instead of hardcoding it:
await supabase.auth.signInWithOtp({
email,
options: { emailRedirectTo: `${window.location.origin}/auth/callback` }
});
await supabase.auth.signInWithOAuth({
provider: 'google',
options: { redirectTo: `${window.location.origin}/auth/callback` }
});
For Google or GitHub login, the provider's own console needs the Supabase callback (https://<project-ref>.supabase.co/auth/v1/callback), not your app's address. That part rarely changes.
The wildcard you should not add
Supabase allows wildcards in Redirect URLs: * matches one path segment and ** matches any path. They are handy for preview deployments, but the docs recommend exact paths for your production site. Avoid broad patterns that match addresses you don't control, such as a wildcard across every vercel.app or netlify.app subdomain. Login links carry tokens, and a redirect to someone else's site hands those tokens to them. Scope preview wildcards to your own team or project name.
A prompt to paste into Lovable, Bolt or Cursor
Supabase auth emails and Google login redirect to localhost:3000.
1. Find every emailRedirectTo and redirectTo in the code.
2. Replace hardcoded URLs with `${window.location.origin}/auth/callback`.
3. Make sure an /auth/callback route exists and finishes the login.
4. Tell me exactly which Site URL and Redirect URLs to set in
Supabase under Authentication, URL Configuration.
While you're in the auth settings, check what your live site exposes. LeakPatrol's free read-only scan looks at your production JavaScript for secret keys and tests whether Supabase tables answer without a login. Related: "Database error saving new user" and "Invalid API key".
Check your app in a minute
Free, read-only, no sign-up. Every problem comes with a plain-English fix and a prompt for your AI tool.
Get the 10-point checklist
Every check we run on AI-built apps, with how to do each one yourself. Straight to your inbox.
Plus the odd security tip. Unsubscribe any time.
Questions
Why does my Supabase magic link go to localhost:3000?
Supabase falls back to the project Site URL when your redirect is missing or not on the allow list, and the Site URL starts as http://localhost:3000. Set it to your live address under Authentication, URL Configuration.
Why is my redirectTo ignored by Supabase?
The exact address must be listed under Redirect URLs in Authentication, URL Configuration. If it is not, Supabase uses the Site URL instead.
Can I use wildcards in Supabase Redirect URLs?
Yes. A single star matches one path segment and a double star matches any path. Use them for local development and your own preview deployments, and exact paths for production.
I changed the settings but the email still opens localhost. Why?
Links in emails sent before the change keep the old address. Request a new email, and check the code does not hardcode localhost in emailRedirectTo.
More guides
- Supabase RLS policy generator (free)
- Is this API key safe in my frontend? Free key checker
- Security scan MCP server for Claude Code, Cursor and other AI agents
- Supabase's October 30 change: what it fixes for your app's security, and what it doesn't
- Supabase "42501 permission denied for table": the safe fix (not GRANT ALL)
- Supabase "new row violates row-level security policy": 5 causes and the safe fix
- Supabase service_role key exposed? What to do in the next hour
- Supabase select returns an empty array but the data is there: the RLS fix
- Supabase "Database error saving new user": find the cause and fix it safely
- Supabase Storage upload: "new row violates row-level security policy" fixed
- Supabase "infinite recursion detected in policy for relation" fixed
- Supabase Edge Function "blocked by CORS policy" fixed
- Supabase "Forbidden use of secret API key in browser" (401) fixed
- Supabase "Invalid API key" and "Legacy API keys are disabled" fixed
- Is your Supabase storage bucket public? What anyone can see, and the fix
- Lovable data exposure study: is your app one of the 24,664?
- Lovable security check: is your Lovable app safe?
- Bolt.new security check: is your Bolt app safe?
- Launch checklist for apps built with Lovable, Bolt and Cursor
- Supabase security check: is your anon key safe? (RLS checker)
- How to check if your API key is exposed on your website
- Are VITE_ env variables secret? How to hide API keys
- Stop users giving themselves your paid plan (Supabase)