A new user signs up on your live app, clicks the confirmation link in their email, and lands on http://localhost:3000, which shows an error page or nothing at all. Or Google sign-in works, then drops them on localhost. Or a password reset email opens a page that doesn’t exist.
In apps built with Lovable, Bolt, v0 or another AI tool on Supabase, this comes down to three things: the Site URL, the redirect allow list, and the redirectTo value your code sends. This guide walks through each one, then the tool-specific cases. For other Supabase problems, see /fix/supabase.
Why it happens
Supabase Auth has to pick a destination whenever a user confirms an email, opens a magic link, resets a password or finishes an OAuth login. Two settings on the project’s URL Configuration page control that choice:
- Site URL. This is the fallback destination, used whenever your code doesn’t pass a
redirectTo. Supabase’s redirect URL docs tell you to switch it fromhttp://localhost:3000to your production address, and point out that email confirmations and password resets depend on it. If nobody changed it, it still points at localhost. - Redirect URLs. An allow list of other addresses your app may send users to. Your code can ask for a specific destination with
redirectTo(oremailRedirectTofor sign-up and magic links), but Supabase only honours it when the URL matches an entry on this list.
When the requested URL doesn’t match, the user is sent to the Site URL instead. Supabase’s troubleshooting article on redirects going to localhost says the exact URL has to be on the Redirect URLs list before redirectTo takes effect. A Supabase team member gave the same explanation in GitHub issue #22242, adding that the match is an exact string comparison: the http version of a URL, or the bare domain, doesn’t cover https://mysite.com/auth/callback.
So there are two routes to localhost: the Site URL was never changed, or your code asked for a URL that isn’t allowed and Supabase fell back to a Site URL that is still localhost.
Step 1: set the Site URL to your production domain
In your Supabase dashboard, open Authentication, then URL Configuration (Supabase lists it among the Auth configuration sections in its general configuration docs), and set Site URL to the address your real users visit, for example https://yourapp.com.
- Use the exact form users land on:
httpsand the samewwwor non-wwwversion your domain redirects to. - If you’ve connected a custom domain, put it here rather than a temporary hosting address.
- For Vercel or Netlify, Supabase’s docs say the Site URL should be your official site address, with preview deployments handled through the allow list (Step 2).
Step 2: add your redirect URLs
On the same page, add every address your app might send users back to. At minimum:
- your production domain, including the exact path your code uses, for example
https://yourapp.com/auth/callback - the other version of your domain (
wwwor non-www) if both are reachable http://localhost:3000/**(or your dev port) if you also develop locally against this project
Wildcards and preview URLs
The allow list accepts wildcard patterns (Supabase redirect URLs):
*matches a run of characters that stops at a separator. Supabase counts.and/as separators.**matches anything, separators included.?matches exactly one non-separator character.
The difference matters. In Supabase’s example, http://localhost:3000/* matches /foo but not /foo/bar or /foo/ (note the trailing slash), while http://localhost:3000/** matches all of them.
For preview deployments, Supabase suggests patterns such as:
- Vercel:
https://*-<team-or-account-slug>.vercel.app/** - Netlify:
https://**--my_org.netlify.app/**
Supabase’s advice is to keep the globstar for local development and previews, and to list the exact redirect path for your production site. Use precise entries for your real domain.
Step 3: check redirectTo and emailRedirectTo in the code
If the dashboard looks right and users still land on localhost, look at what your code asks for. Search the project for redirectTo, emailRedirectTo and localhost.
The calls to look for:
- Sign-up:
supabase.auth.signUp({ email, password, options: { emailRedirectTo: '...' } })sets where the confirmation link goes (signUp reference). - Magic links:
supabase.auth.signInWithOtp({ email, options: { emailRedirectTo: '...' } }). Note the option name: magic links useemailRedirectTo, notredirectTo(signInWithOtp reference). - OAuth:
supabase.auth.signInWithOAuth({ provider, options: { redirectTo: '...' } })(signInWithOAuth reference). - Password reset:
supabase.auth.resetPasswordForEmail(email, { redirectTo: '...' }). See the next section.
Problems to look for in AI-generated code:
- A hard-coded
http://localhost:3000left over from development. Replace it with your production URL, or build it from an environment variable. - A URL built from
window.locationthat comes out wrong. One user in GitHub issue #22242 appended a path towindow.location.href, which already ended in a slash, so the URL had a double slash and no longer matched the allow list. - A path that isn’t allowed. If the code sends users to
/auth/callbackbut the allow list only has the bare domain with a single*, it won’t match. - A misnamed option. Passing
redirectTotosignInWithOtp, where the option isemailRedirectTo, leaves Supabase with no redirect, so it uses the Site URL.
Supabase’s redirect docs include a small getURL() helper for Vercel. It reads a site URL environment variable first, falls back to Vercel’s deployment URL, and adds https:// and a trailing slash where they’re missing. It’s a handy pattern for avoiding hard-coded addresses.
PKCE and the callback route
Apps that use the PKCE flow (Next.js apps with server-side auth, for example) get the user back with a ?code= parameter, which the app swaps for a session by calling exchangeCodeForSession(code). According to Supabase’s PKCE flow docs, that code expires after 5 minutes and works only once, and the exchange has to happen in the same browser, on the same device, that started the flow.
So the callback URL must be on your allow list, and the route must exist on your production deployment. If users reach the right domain but see a 404 on the callback page, check your hosting setup too; 404s and missing environment variables on Vercel and Netlify covers that side.
Password reset link goes to localhost
Reset emails follow the same rules as every other auth email, with one extra trap: the reset link has to land on a page where the user can choose a new password.
- Pass
redirectTotoresetPasswordForEmail(resetPasswordForEmail reference). Point it at your change-password page, for examplehttps://yourapp.com/account/update-password. Supabase’s password guide says that address must be in your redirect URLs. If the call passes noredirectTo, the link goes to the Site URL. - Allow-list the reset page itself. Add the full path (
https://yourapp.com/account/update-password), or a/**pattern on your domain that covers it. A bare domain entry or a single*won’t match a nested path. - Check the Reset password email template. If the link in it starts with
{{ .SiteURL }}, it ignores yourredirectTo. In GitHub issue #45676, the reporter’s reset template built its link from{{ .SiteURL }}, and the reset emails pointed at localhost. See the email templates section below. - Send a fresh reset email after each change. Links in older emails keep the address they were created with.
Bolt’s authentication settings page adds a practical point: without specific instructions, a generated reset flow can drop users on the dashboard rather than on a screen for setting a new password. Ask the AI tool for a dedicated reset-password route and make sure the link points there.
If the reset link reaches the right page but then shows “Auth session missing” or says the link has expired, the redirect is working and the problem is the code exchange. The PKCE notes above (5-minute, single-use code, same browser) are the first things to check, and Supabase reset password not working covers the rest of the reset flow.
Step 4: preview works, published app redirects
A login that works in your AI tool’s preview but sends users to localhost (or back to the login page) on the published app means the published address is missing from the Site URL or allow list. Each tool handles this differently.
Lovable
Lovable’s authentication docs place both settings in the Advanced area of your app’s auth settings, at More → Users → Settings → Advanced → Redirect URLs.
- Built-in backend (Lovable Cloud): Lovable maintains both settings. Publishing points the Site URL at your published address (for example
your-app.lovable.app) unless it already uses a domain you own, and connecting a custom domain puts that domain on the redirect list. The redirect list shows the preview and published addresses Lovable added alongside your own entries. - Your own Supabase project: Lovable registers the addresses it hosts in that project’s redirect list. Setting the Site URL, and adding any address Lovable doesn’t host, is up to you in the Supabase dashboard (Step 1 and Step 2).
- Addresses outside Lovable (external hosting, a local copy): add them yourself, ending in
/**. Lovable’s docs say it rejectslocalhostentries, so test locally on an address likehttp://127.0.0.1:5173and allow-listhttp://127.0.0.1:5173/**. They also say that when Lovable rewrites the list, it drops other addresses on Lovable domains, so use a domain you own. The list holds up to 50 URLs.
If Google sign-in runs on your own Google OAuth credentials, register a redirect URI for each new domain in Google Cloud Console as well (see the OAuth section below). More Lovable fixes: /fix/lovable.
Bolt
Bolt publishes to a free bolt.host address, and paid plans can attach a custom domain (Bolt publishing docs). On a Bolt Database project, the auth settings have a Site URL and a URI allow list under the advanced options (Bolt authentication settings):
- Bolt’s docs say a new project’s Site URL is
localhost:3000, and that publishing doesn’t always update them for you, especially for apps on more than one domain. - Bolt keeps any manual change you make, so if you edited these settings yourself, re-check them after changing your
bolt.hostname or adding a custom domain. - The allow list takes comma-separated patterns, for example
https://your-app.bolt.host/**. Include any reset-password route. - Google sign-in won’t work inside the Bolt preview, because Google’s OAuth flow blocks iframes. Test it on the published site.
If your Bolt app is connected to your own Supabase project, make these changes in that project’s URL Configuration page instead. More Bolt fixes: /fix/bolt.
v0
v0 deploys to Vercel. According to v0’s deployment docs, each working branch gets a preview deployment at its own unique URL, while publishing updates a stable production URL (the provided vercel.app domain or a custom domain you select).
- Set the Site URL to the production domain users visit.
- Add your exact production callback path to Redirect URLs.
- If you test sign-in on preview deployments, add the Vercel preview pattern from Step 2.
- Set
NEXT_PUBLIC_SITE_URL(or whatever variable your code reads) for the Production environment in the Vercel project, so theredirectToyour code builds isn’t localhost.
More v0 fixes: /fix/v0.
Custom domains
When you move to a custom domain, or add one later:
- Update the Site URL to the custom domain (or confirm the tool did it for you).
- Add the custom domain, and any
wwwvariant, to the Redirect URLs. - Add the new domain’s callback at any OAuth provider that uses your own credentials.
- Keep preview wildcards for your host if you test sign-in on preview deployments.
On Lovable, a project’s other connected domains redirect to the primary domain (Lovable custom domain docs), so use the primary domain as your Site URL. If the domain itself isn’t working yet, fix that first: see Lovable custom domain not working or, for Replit apps, Replit custom domain not working.
Google, GitHub and other OAuth providers
OAuth has two separate redirect settings, and they’re easy to mix up:
- At the provider (for example Google Cloud Console). Under Authorized redirect URIs, you enter the callback URL of your Supabase project, not your app’s URL (Supabase Google login). Your app’s own address goes under Authorized JavaScript origins.
- In Supabase. Your app’s URL (where users go after login) goes in the Redirect URLs allow list, and in
redirectToin your code.
If users reach localhost after Google sign-in, look at the Supabase side first (Site URL, allow list or redirectTo). If Google itself shows an error about the redirect URI, the provider side is wrong. If Google shows “403: disallowed_useragent” inside an app like Instagram or Facebook, that’s an in-app browser problem, not a redirect one: see Google sign-in 403 disallowed_useragent.
Email templates that hard-code the Site URL
Supabase’s email templates can build links from different variables:
{{ .SiteURL }}holds your project’s Site URL.{{ .RedirectTo }}holds whatever redirect URL your code passed tosignUp,signInWithOtp,signInWithOAuth,resetPasswordForEmailorinviteUserByEmail.{{ .ConfirmationURL }}is the full confirmation link, with the redirect already included.
If someone customised a template so the link starts with {{ .SiteURL }}, every email goes to the Site URL whatever your code passes. Supabase’s redirect docs show the fix: swap {{ .SiteURL }} for {{ .RedirectTo }} in templates when your code uses redirectTo. Check the Confirm sign up, Magic link or OTP and Reset password templates.
If the emails aren’t arriving at all, that’s a separate problem with its own fixes: see Supabase auth emails not sending.
Still redirecting after you changed it
If you’ve fixed all three settings and it still goes to localhost:
- Use a fresh email. Links in emails sent before your change still carry the old address. Request a new confirmation or reset email.
- Test in a private window with a new account, so an old session or cached page isn’t involved.
- Check you edited the right project. A separate development and production Supabase project, or a preview and a published app on different backends, means two sets of settings.
- Check your hosting environment variables. If your code builds the redirect from an environment variable, make sure it’s set in production, and rebuild if it’s baked in at build time.
- Restarting the project. In GitHub issue #45676, a user reported that the dashboard showed the new Site URL while auth flows kept using localhost, and later wrote that restarting the project from the dashboard fixed it for them. Treat that as a user report, not an official fix, and try it only after checking everything above.
Then run every auth flow once on the live domain: sign up, confirm email, log in, log out, reset password, and each social login. If you’ve added CAPTCHA to sign-up (stop fake bot signups with Supabase CAPTCHA), include it in the test run. For Lovable-specific login problems beyond redirects, see Lovable app not working.
FAQ
Why does my confirmation email link go to localhost?
Either the Site URL is still http://localhost:3000, or your sign-up code passes an emailRedirectTo that isn’t on the Redirect URLs allow list, so Supabase uses the Site URL instead. Also check that the email template doesn’t hard-code {{ .SiteURL }}.
Why does my password reset email open localhost?
The reset link uses the redirectTo you pass to resetPasswordForEmail, but only if that exact page is on your allow list. If the call has no redirectTo, the page isn’t allowed, or the Reset password template builds its link from {{ .SiteURL }}, Supabase sends the user to the Site URL, which defaults to localhost. Fix those, then request a new reset email.
I changed the Site URL but it still redirects to localhost. Why?
Old emails still contain the old link, so request a new one. Then check that your code isn’t passing a hard-coded localhost redirectTo, that you changed the right Supabase project, and that your templates use the right variable.
Do I need to add every preview URL to the allow list?
No. Supabase’s allow list accepts wildcards, so one pattern such as https://*-<team-or-account-slug>.vercel.app/** covers Vercel previews, and https://**--my_org.netlify.app/** covers Netlify previews. Supabase recommends exact URLs for production, though. On Lovable’s built-in backend, Lovable adds the preview and published addresses for you.
Do I need to add both www and non-www?
If users can reach both, yes. Matching is done on the URL as written, so https://www.yourapp.com and https://yourapp.com are separate entries. Simplest is to redirect one to the other at your host and use that one as your Site URL.
Why are users logged out after redirecting?
If the redirect itself is right, check where it lands. With the PKCE flow, the code in the link can only be exchanged in the same browser and device that started sign-in, within 5 minutes, and only once. A user who requests a magic link on a laptop and opens it on a phone, or opens an old link, arrives without a session. Sessions are also stored per site address, so signing in on yourapp.com and being sent to www.yourapp.com (or from a preview address to production) can look like a logout. Make the Site URL, redirectTo and the address users start on the same.
Where do I change this in a Lovable Cloud project vs my own Supabase project?
On Lovable’s built-in backend, the settings are under More → Users → Settings → Advanced, and Lovable updates them when you publish or connect a custom domain. If your Lovable app is connected to a Supabase project you own, set the Site URL and any non-Lovable addresses in that project’s Supabase dashboard under Authentication → URL Configuration. Lovable only adds its own addresses there.
Comments