November 22, 2026 · 9 min read · Thomas Osayi
Supabase auth redirect URL not working? Fix localhost, preview and production redirects
Supabase confirmation or magic links sending users to localhost:3000 or the wrong page? Fix the Site URL, the Redirect URLs allow list, wildcards and emailRedirectTo.
The symptom usually looks like this. A user signs up on your live site, opens the confirmation email, clicks the link, and the browser shows "This site can't be reached. localhost refused to connect." Or the magic link works but drops them on the homepage instead of the dashboard. Or Google sign-in works on your laptop and quietly sends people back to the preview URL in production. The code says redirectTo or emailRedirectTo with the right address, and Supabase seems to ignore it.
It is not ignoring you at random. Supabase Auth checks every redirect against a list you control in the dashboard, and when the check fails it falls back to a default. This is one of the most common issues I see in apps built with Lovable, Bolt or Cursor on top of Supabase, and it is almost always fixed in the dashboard in ten minutes. Here is how it works and how to fix each version of it.
Why is my Supabase auth redirect URL not working?
In most cases the URL you pass in code is not on the Redirect URLs allow list, so Supabase sends the user to the Site URL instead.
Supabase keeps two settings under Authentication, then URL Configuration, in the dashboard. The Site URL is the default destination after sign-in and the base used to build links in your auth emails. The Redirect URLs list is every other address your app is allowed to send users to. When your code calls signUp with options.emailRedirectTo, or signInWithOAuth or signInWithOtp with options.redirectTo, Supabase compares that value against the list. Supabase's own troubleshooting article on being redirected to the wrong URL puts it plainly: you must set the exact URL in the Redirect URLs setting.
Here are the causes, ranked by how often I find them:
- The Site URL is still http://localhost:3000, the default from when the project was created.
- The redirect URL in code is not on the allow list, or differs by protocol, port, trailing path or www.
- The email template builds its link from the SiteURL variable, so your redirect value never reaches the email.
- Preview deployments use a new URL per commit and there is no wildcard entry for them.
- The app reads the redirect base from an environment variable that is undefined in production, so the redirect becomes a relative path or "undefined/auth/callback".
How do I stop Supabase redirecting to localhost?
Change the Site URL to your real production address and save, then send yourself a fresh email, because links already sitting in inboxes were built with the old value.
Open your project in the Supabase dashboard, go to Authentication, then URL Configuration, and set Site URL to the exact origin users visit, for example https://www.yourbrand.com. Pick the version you actually serve. If your domain redirects the apex to www, use the www version, because a redirect hop can strip the session fragment from the URL on some setups.
Then trigger a new signup or password reset and check the link inside the email before clicking it. Hover over the button or copy the link address. It should contain your production domain in the redirect_to parameter. If it still says localhost, either the save did not stick, you are looking at an old email, or your template overrides the link, which I cover below.
How do the Redirect URLs allow list and wildcards work?
Each entry is a pattern, and Supabase lets you use wildcards so one entry can cover many paths or subdomains.
According to the Supabase Redirect URLs guide, the matching rules are:
- A single asterisk matches any run of characters except the separators, and the separators are the dot and the forward slash.
- A double asterisk (two asterisks in a row) matches any sequence of characters, separators included.
- A question mark matches one non-separator character.
That separator rule trips people up. The docs give the example that http://localhost:3000/ followed by a single asterisk matches /foo but not /foo/bar and not /foo/ with a trailing slash. If your callback lives at /auth/callback, a single-asterisk pattern on the root will not match it. Use the double asterisk at the end of the path for local development so every nested route is covered.
For production, the Supabase docs recommend listing the exact redirect path rather than a wildcard, for example https://www.yourbrand.com/auth/callback. An exact entry is easier to reason about and cannot be abused to send a session somewhere you did not intend.
A practical list for a typical app:
- https://www.yourbrand.com/auth/callback (exact, production)
- http://localhost:3000/ followed by a double asterisk (local development)
- https://, then a single asterisk, then -your-team-slug.vercel.app/ followed by a double asterisk (Vercel previews)
How do I set emailRedirectTo and redirectTo correctly?
Pass a full absolute URL that matches an allow list entry, and build it from a variable that exists in every environment.
For email and password signups, the option is emailRedirectTo inside the options object of supabase.auth.signUp. The Supabase JavaScript reference shows it as options: { emailRedirectTo: 'https://example.com/welcome' }. For OAuth providers such as Google, the option is redirectTo inside the options of signInWithOAuth. For magic links it is emailRedirectTo inside signInWithOtp, and for password resets it is redirectTo in resetPasswordForEmail.
The mistakes I see most:
- A relative path like "/dashboard". It has to be absolute, including https://.
- window.location.origin used in server code, where window does not exist.
- An environment variable such as NEXT_PUBLIC_SITE_URL that is set locally in .env.local but never added on Vercel, so the redirect becomes "undefined/auth/callback". My post "Environment variables undefined on Vercel? Every cause and fix" walks through that one.
- A trailing slash mismatch. If the allow list says /auth/callback and the code sends /auth/callback/ with a slash, an exact entry will not match.
The safe pattern is a small helper that returns the production URL from NEXT_PUBLIC_SITE_URL in production, the Vercel preview URL in previews, and http://localhost:3000 locally, then appends your callback path.
Why do my email links still use the Site URL?
Because the email template builds the link itself, and a hand-edited template that uses the SiteURL variable will ignore whatever redirect you passed.
Supabase email templates, under Authentication, then Emails, have variables. ConfirmationURL is the full link Supabase builds, including the token and your redirect target. SiteURL is just your Site URL. RedirectTo is the redirect value you passed to signUp, signInWithOtp or inviteUserByEmail, and the Supabase Email Templates docs note it must be on the allow list. TokenHash lets you build your own link.
If your template was customized to something like the SiteURL variable followed by /auth/confirm?token_hash=, every email goes to the Site URL no matter what your code sends. The Redirect URLs guide says that when you use redirectTo, you should replace SiteURL with RedirectTo in your templates.
There is a second email problem that looks like a redirect bug. Some corporate email scanners open links before the user does. The Email Templates docs describe Microsoft Defender's Safe Links consuming the confirmation link, so the user then sees "Token has expired or is invalid." The fix there is an OTP code or a landing page with a button, not a redirect change.
How do I handle localhost, Vercel previews and production together?
Use one exact production entry, one wildcard for previews, one wildcard for localhost, and make your code pick the right base URL per environment.
Vercel gives every commit a unique URL in the form project-name, a hash, then your team slug, followed by .vercel.app. The Supabase docs suggest adding a wildcard that matches any subdomain ending in your team or account slug on vercel.app, followed by a double asterisk, and reading the deployment URL at runtime. Vercel exposes it as NEXT_PUBLIC_VERCEL_URL for Next.js apps, without the https:// prefix, so add it yourself.
For Netlify, the docs show a similar pattern using the double-hyphen preview format. For Lovable previews, add the preview domain your project actually uses. If you are moving off the builder's hosting, my guide "How to move a Lovable app to Vercel and your own domain" covers the full checklist.
For local development with the Supabase CLI, the dashboard settings do not apply. Set site_url and additional_redirect_urls under the auth section of supabase/config.toml, then restart the local stack so the change loads.
What about Google sign-in and the PKCE callback?
OAuth adds a second allow list on the provider side, and a missing callback route in your app produces errors that look like redirect problems.
For Google, the Authorized redirect URI in your Google Cloud OAuth client must be your Supabase project's callback, https://your-project-ref.supabase.co/auth/v1/callback, not your own site. If that is wrong, Google shows "Error 400: redirect_uri_mismatch" before Supabase is even involved.
After Google hands the user back, Supabase redirects to your redirectTo URL with a code. In a Next.js App Router app using the server-side flow, that URL should hit a route such as app/auth/callback/route.ts that calls exchangeCodeForSession with the code, sets the session cookies, then redirects to the dashboard. If that file does not exist, users land on a 404 or a page that thinks they are signed out. For email confirmation with server-side auth, a route such as app/auth/confirm/route.ts reads token_hash and type and calls verifyOtp.
If authentication fails, Supabase still redirects to your URL and puts error details in the URL fragment. Check the address bar for error and error_description before assuming the redirect itself is broken.
A worked example: a booking app stuck on localhost
Here is an illustration with a made-up business. A dog grooming studio builds a booking app in Lovable with Supabase auth, moves it to Vercel on groomstudio.com, and new customers report that the confirmation link "goes nowhere."
The checks, in order:
- The email link contains redirect_to=http://localhost:3000. The Site URL was never changed. I set it to https://www.groomstudio.com.
- The code calls signUp with emailRedirectTo built from window.location.origin plus /welcome. That is fine in the browser, but /welcome is not on the allow list. I add https://www.groomstudio.com/welcome as an exact entry.
- The confirmation template was customized to use SiteURL. I switch it back to ConfirmationURL.
- Previews break for the owner when testing. I add the vercel.app wildcard for the team slug.
- Local development still works because localhost with a double asterisk sits in the allow list.
Total time is under an hour, most of it testing with fresh emails. Nothing in the app code needed rewriting.
When should I get help?
Get help when the dashboard settings are correct and fresh emails still misbehave, because then the problem lives in your callback routes, cookies or middleware.
Typical signs: the session appears for a moment and then disappears, sign-in works on Chrome but not Safari, or the app loops between the login page and the dashboard. Those come from how the session is stored and refreshed, not from the allow list. They often sit next to other launch issues, which I list in "Your Lovable or Bolt app works locally. Here is what breaks at launch." If you are not sure your tables are protected once users can sign in, read "Is your Lovable or Bolt app leaking data? Check Supabase row level security" before you open signups.
A single redirect bug fits my Quick Fix from $60, delivered in about two days. If auth is one of several launch blockers, Fix Plus Features from $200 covers up to three fixes plus one small feature.
The bottom line
When a Supabase auth redirect is not working, start in the dashboard, not the code. Set the Site URL to your production domain, put localhost and preview patterns in the Redirect URLs list, use exact entries for production paths, and remember that a single asterisk stops at dots and slashes. Then check that your email templates use the redirect value and that the URL you pass in emailRedirectTo or redirectTo is absolute and built from a variable that exists in production. Test every change with a brand new email, never an old one.
Questions, answered in one line
Why does my Supabase confirmation email redirect to localhost:3000?
Because the Site URL in Authentication, URL Configuration is still http://localhost:3000, and Supabase uses the Site URL whenever no allowed redirect is supplied.
Do Supabase Redirect URLs support wildcards?
Yes, a single asterisk matches characters up to the next dot or slash, and a double asterisk matches any sequence, including nested paths.
What is the difference between Site URL and Redirect URLs in Supabase?
The Site URL is the default destination and the base for email template links, while Redirect URLs is the allow list of other places your code may send users after sign-in.
Where do I set redirect URLs for local Supabase development?
When you run Supabase locally with the CLI, set site_url and additional_redirect_urls under the auth section of supabase/config.toml and restart the local stack.
Can someone fix my Supabase auth redirects for me?
Thomas Osayi fixes a single bug like a broken auth redirect from $60 in about two days, and handles up to three fixes plus a small feature from $200.
Sources
- Redirect URLs Supabase Docs
- Why am I being redirected to the wrong url when using auth redirectTo option? Supabase Docs
- Email Templates Supabase Docs
- JavaScript: Create a new user (signUp) Supabase Docs
Related articles
- Environment variables undefined on Vercel? Every cause and fix
- How to fix a CORS error on a Next.js API route
- Firestore "Missing or insufficient permissions": what triggers it and how to fix it
- Firebase auth/unauthorized-domain: how to fix it on Vercel, previews and custom domains
Fix, finish and launch your AI-built app
Built your app with Lovable, Bolt, v0, Replit or Cursor and got stuck? I fix the bugs, connect auth and payments, clean up the code and deploy it to production.
See the service