Mendlark / Guides

Supabase confirmation or magic link redirects to localhost: how to fix it

A new user signs up on your live app, clicks the confirmation email, and lands on http://localhost:3000 with "This site can't be reached". Magic links and password reset emails do the same. Your app is fine; Supabase just doesn't know your live address yet. Here's the fix.

Stuck on this? Get it fixed for €49.

Fixed in 48 hours or you don't pay. Launch deal for the first 5 customers (normally €79). You get the tested fix as a pull request, so nothing changes until you merge it.

Get it fixed for €49

Why it happens

Every auth email from Supabase contains a link back to your app. Supabase picks the address from two places: the emailRedirectTo or redirectTo your code sends, and the Site URL in your project settings. A new project starts with the Site URL set to http://localhost:3000. If your live address isn't set and allowed, Supabase falls back to localhost.

1. Set the Site URL to your live address

In the Supabase dashboard open Authentication, then URL Configuration. Set Site URL to your real address, for example https://yourapp.com, with no trailing slash. This is the default for every auth email.

2. Add your addresses to Redirect URLs

On the same page, add every address your app may send users back to under Redirect URLs. If your code asks for an address that isn't on this list, Supabase quietly ignores it and uses the Site URL instead, which is why the link still goes to localhost even after you changed the code. Typical entries:

https://yourapp.com/**
https://www.yourapp.com/**
http://localhost:5173/**

Add your Vercel or Netlify preview address too if you test there, for example https://*-yourteam.vercel.app/**.

3. Send the right address from your code

Don't hard-code localhost. Build the address from wherever the app is running:

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

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

Search your code for localhost. AI tools often leave it in a config file or an env variable such as VITE_SITE_URL or NEXT_PUBLIC_SITE_URL. If you use one, set it to the live address in your host's environment settings and redeploy (see env variables undefined in production).

4. Check the email templates

Under Authentication then Emails, look at the confirm signup, magic link and reset password templates. They should use {{ .ConfirmationURL }}. If someone pasted in a link with localhost or an old domain, replace it.

5. Make sure the page the link opens actually signs the user in

Once the link reaches the right address, the page it opens has to finish the sign-in. In Next.js apps using @supabase/ssr that's an /auth/callback route that swaps the code for a session. If users land on the right page but aren't logged in, or bounce back to login, see our guide on the Supabase auth redirect loop on Vercel.

Old emails keep their old link, so test with a brand new sign-up after each change.

Quick checklist

  • Site URL is your live address
  • Live, www and local addresses are in Redirect URLs
  • Code uses window.location.origin or a live env variable, never a hard-coded localhost
  • Email templates use {{ .ConfirmationURL }}
  • The landing page completes the sign-in

Stuck on this? Get it fixed for €49.

Fixed in 48 hours or you don't pay. Launch deal for the first 5 customers (normally €79). You get the tested fix as a pull request, so nothing changes until you merge it.

Get it fixed for €49

Still stuck?

Mendlark fixes this kind of problem for a fixed €49 (launch price, normally €79). We agree the problem first, test the fix and send it as a pull request, so nothing changes in your app until you merge it. If we can't fix it, you don't pay. Get the €49 fix, or start with a free scan.

Not sure what else is wrong? Paste your app link into the free instant check and get a plain-English list of problems in seconds.