Open Supabase’s Authentication settings and look at the Site URL field. If it still reads http://localhost:3000 after you have deployed, every confirmation email and magic link you send will contain that address, and your users will click through to a dead page on their own machine. This is the most common supabase auth redirect url mistake we find in apps built with Lovable, Bolt or Cursor: the builder got auth working against a local dev server and nobody ever pointed it at production once the app went live.
We’ve covered the data-access side of Supabase problems in our piece on common Supabase mistakes, which is mostly about row-level security and who can read what. This is a different and much narrower family of bugs. It doesn’t leak data, it just stops people getting in, which from a founder’s point of view is arguably worse on launch day.
How the redirect flow actually works
Supabase auth doesn’t hand a user a session the moment they click a link. When someone confirms a signup email, finishes a magic-link flow, or comes back from Google or GitHub OAuth, Supabase redirects their browser to a URL built from two settings in the dashboard, plus one route you have to build yourself.
The first setting is the Site URL, under Authentication → URL Configuration. This is the default base Supabase falls back to when it generates a link and no other redirect was specified. The second is the Redirect URLs list, an allow-list of every exact URL Supabase is permitted to send a browser back to. If a URL isn’t on that list, Supabase refuses the redirect outright rather than silently falling back to something safe.
The route itself is usually something like /auth/callback. It reads a code parameter off the query string and exchanges it for a session before sending the user on to the dashboard. If that exchange doesn’t happen, or happens after the page has already decided the user isn’t logged in, you get a user with a valid code and no session.
Three moving parts, three places for an AI-generated app to get it half right. Most do, because during development the builder is testing in the same browser tab that already has cookies set, so the gap between “looks logged in” and “actually has a session” never shows up until a stranger tries it.
The four symptoms we see on repeat
Confirmation and magic-link emails point to localhost. The Site URL was never changed from the scaffold default. Every email Supabase sends uses it as the base, so users get a link to localhost:3000/auth/confirm that only works on the machine the app was built on.
“Redirect URL not allowed” error on login. The production domain was never added to the Redirect URLs allow-list, or it was added with a mismatched trailing slash. Supabase matches these exactly, so https://yourapp.com/auth/callback and https://yourapp.com/auth/callback/ are treated as two different entries.
The login-and-dashboard loop. The user logs in, lands on the dashboard for a split second, then gets bounced back to the login page, sometimes repeatedly. This is almost always a race condition: a client-side route guard checks for a session before the callback route has finished exchanging the code, decides there’s no user, and redirects to login, which then finds a session has since appeared and redirects back. Round and round.
Users get logged out on every refresh. Usually an environment variable problem rather than a redirect one. The app works fine in the builder’s preview but loses the session in production because the anon key or project URL baked into the client is wrong for that environment. We’ve written separately about how preview and production environment variables drift apart, and this is one of the more annoying ways that shows up to an end user.
Fixing each one, step by step
Start with the dashboard settings, since they take two minutes and rule out half the symptoms above.
- In Authentication → URL Configuration, set Site URL to your actual production domain, with no trailing slash:
https://yourapp.com. - In the same screen, add every environment your app runs in to the Redirect URLs list: production, staging, and if your host spins up preview deployments on every pull request, a wildcard entry such as
https://*.yourhost.app/**. - Redeploy and trigger a fresh confirmation email to check the link in it now points at the right domain.
If you’re still hitting “redirect URL not allowed” after that, check for a mismatch between what your code actually passes as redirectTo and what’s on the allow-list character for character. A stray slash, http instead of https, or a www. that’s present in one place and not the other will all fail silently from the user’s point of view and loudly in Supabase’s logs.
For the login-dashboard loop, look at your callback route and confirm it awaits the code exchange before redirecting anywhere:
export async function GET(request: Request) { const code = new URL(request.url).searchParams.get("code"); if (code) { const { error } = await supabase.auth.exchangeCodeForSession(code); if (error) { return NextResponse.redirect(new URL("/login?error=auth", request.url)); } } return NextResponse.redirect(new URL("/dashboard", request.url));}Then check whatever guards your dashboard route. If it reads the session from a client-side store that hasn’t rehydrated yet, it will decide the user is logged out before the cookie set by the callback has actually landed. The fix is to read the session server-side, or to show a loading state instead of redirecting until the client has checked at least once.
For the logged-out-on-refresh symptom, confirm the production build is actually using production values for SUPABASE_URL and SUPABASE_ANON_KEY, not values baked in at build time from a .env file meant for local development. If your app has no concept of persistent sessions at all yet, that’s a sign auth was bolted on quickly. Our guide to adding authentication properly to a vibe-coded app covers the session handling piece in more depth than we can here.
One more thing worth checking while you’re in the email settings: if the links are correct but the emails themselves aren’t arriving, that’s a separate problem with sender reputation, not redirects, and we’ve written about why emails from AI-built apps end up in spam if that’s what you’re actually seeing.
Test it properly before you call it done
A redirect bug that only shows up for a brand new user is exactly the kind of thing that survives weeks of the founder’s own testing, because the founder’s browser already has a valid session sitting in it. Test it the way a stranger would:
- Sign up with a new email address in a private or incognito window.
- Open the confirmation email on a different device, or at least a different browser profile, and click the real link rather than copying the URL.
- Confirm it lands on your live app, not localhost, and that it actually logs you in rather than showing a generic “confirmed” page.
- Refresh the dashboard five or six times in a row. If you get bounced to login even once, you have a race condition.
- Log out, log back in with the same account, and refresh again.
- If you offer Google or GitHub sign-in, test that path separately. It uses its own redirect entry and fails independently of the email-based flow.
None of this takes long, but it has to happen in a second browser or a second device. Testing auth in the same tab you built it in will tell you almost nothing about what a new user is about to experience.
Login loops driving users away? We’ll fix the flow. Get a free assessment and we’ll find out exactly where your redirects are breaking.