By Andrey Kamensky · · 6 min read

Preview Looks Fine, the Published Site Looks Broken: Explaining It to the Agent


Your Lovable app works in preview and breaks on the published domain. The five host-dependent causes (auth allowlists, env, routing) and the fixes.

The Problem

Friday afternoon, the demo with the first real customer. You open the published site, the one on the actual domain, and click “Sign in with Google”. The screen flashes, comes back with a redirect to localhost:3000, and dumps you on a dead page. You open the Lovable preview: same button, same account, works instantly. You type “publish breaks my login” into the agent, and it confidently rewrites the auth screen. Twice. The published site gets worse.

This is the most common “the preview looks fine” bug in AI-built apps, and the explanation is not a bug in your code. Preview and published are two different hosts, and a web application has several layers that care deeply about which host they run on. The preview URL was registered everywhere it needed to be, because the setup guides tell you to. The production domain was registered almost nowhere, because nothing reminds you. Same React, different host, different rules.

Here are the five places the host difference bites, in the order they usually bite.

1. The auth redirect allowlist

Supabase Auth only sends the browser to URLs it already trusts. The trust list is the URL Configuration page: a Site URL plus explicit Redirect URLs, with wildcard patterns allowed (Supabase redirect URLs). When your app calls redirectTo with a URL that isn’t on the list, the redirect silently falls back to the Site URL, which in a Lovable project often still points at the preview host or a localhost leftover (Supabase KB: redirects going to localhost).

Lovable’s own setup guide walks you through adding the preview URL to Supabase and ends with the note everyone skips: click Save at the bottom (Lovable’s Supabase auth guide). The production domain needs the same treatment: https://yourdomain.com/** as a redirect pattern, the domain as Site URL, saved. Until then, login loops, lands on localhost, or “succeeds” without a session, which is the scariest variant because nothing throws an error.

2. The OAuth providers have their own allowlists

Supabase is one layer. “Sign in with Google” also configures Google: the OAuth client in Google Cloud has authorized redirect URIs, and the production callback (https://yourdomain.com/…/callback) must be listed there too, exactly. A provider-side mismatch produces Google’s classic redirect_uri_mismatch error, which at least tells you where it died, unlike the silent Supabase fallback. Every provider you enabled in preview needs the production callback in its own console. This is the step agents miss most, because the fix lives in Google’s console, not in the codebase they can see.

3. Environment variables are baked at build time

Vite-style frontends inline environment variables when the build runs. A variable set in the preview environment but missing (or differently named) in the published build doesn’t error at build time; it becomes undefined at runtime, and the app degrades somewhere far from the cause: an empty dashboard, a “network error” on submit, a map that won’t load. After publishing, check the built bundle actually carries the production values, not the preview ones. Hosted Supabase URLs are public by design, so the common failure isn’t a leaked secret, it’s a missing key.

4. SPA routing needs rewrites on the host

The preview runs inside Lovable’s own serving environment, which already handles single-page-app routing. Your published domain might not. The symptom: the homepage works, but pasting yourdomain.com/dashboard directly, or refreshing while deep in the app, returns a 404 from the host. The code is fine; the host needs a rewrite rule sending unknown paths to index.html. Every static host has a knob for this, and it’s a one-line config, but it’s host configuration, invisible from inside the codebase, and the agent will happily “fix” the router for an hour if you let it.

5. Preview runs the draft; production runs what you published

The subtlest one. In Lovable, accepting a draft changes the backend immediately (schema, storage, functions), while the UI waits for Publish (the dev/prod separation guide covers the full model). The practical consequence cuts both ways: the preview can show a half-built screen wired to a half-migrated database, and the published site can serve last week’s UI against this morning’s schema. Either side can look “broken” while both are technically working as designed. Related and quieter: in preview you’re usually logged in as the project owner, so Row Level Security policies that block the anonymous or plain-authenticated role never get exercised. Published, real visitors hit those policies, and lists come back empty. The app looks broken; the policies are just doing what someone wrote.

How to Explain It to the Agent

The title of this article is a real workflow question, and the answer is diagnostic framing. “The published site looks broken” sends the agent into the code, where the bug isn’t. Instead, hand it the host difference as a hypothesis:

Login works on the Lovable preview URL and fails on the published domain. After Google sign-in the browser lands on localhost instead of the domain. Check where redirect destinations are configured (Supabase URL Configuration and the Google OAuth client) for the production domain, and compare against the preview setup. Don’t rewrite the auth screens.

One host-specific hypothesis per prompt, with the failing flow and the exact landing URL. That turns the agent from a random rewriter into a diagnostician. The general discipline behind this (one change, one check, no shotgun edits) is the same one that keeps AI-built apps from regressing, and it’s covered in why every new prompt breaks something that already worked.

The Ten-Minute Pre-Publish Checklist

Run this once per custom domain, before the demo, not after:

CheckWherePass condition
Redirect URLs include the domainSupabase Auth URL Configurationhttps://yourdomain.com/** listed, saved
Site URL is the domainSupabase Auth URL ConfigurationNot localhost, not the preview host
OAuth callbacks per providerGoogle Cloud / GitHub / etc. consolesProduction callback URI listed exactly
Production env values in the buildPublish settings / build configBundle carries production keys
SPA rewrites on the hostHost settingsDirect navigation to /dashboard renders, not 404s
Logged-out smoke testPrivate window, real domainKey screens load as anonymous and as a fresh user

Ten minutes here beats an afternoon of agent archaeology in front of a customer.

TL;DR

Symptom on the published siteHost-dependent causeFix location
Login loops or lands on localhostSupabase redirect allowlist missing the domainSupabase URL Configuration
redirect_uri_mismatch from GoogleProvider console lacks the production callbackGoogle Cloud / provider console
Empty config values, “network errors”Env variables baked at build time, missing in productionPublish/build settings
Deep links and refreshes 404SPA rewrite rules absent on the hostHost config
Lists empty for real visitorsRLS policies never exercised by the owner-logged-in previewDatabase policies
Preview shows features production lacksPreview runs the draft; production runs the last publishAccept draft, publish deliberately

Sources & further reading

Frequently asked questions

Why does my Lovable app work in preview but break on the published site?

Because preview and published are different hosts, and several layers of a web app are host-dependent: auth redirect allowlists, OAuth provider settings, environment variables baked at build time, SPA routing rules, and which version of the app (draft vs published) each host actually runs. The React code is the same; the host is not.

Why does login redirect to localhost after publishing my Lovable app?

Supabase Auth only redirects to URLs listed in its URL Configuration. The preview URL was added there (Lovable's setup guide says to add it), the production domain wasn't. When the published site requests a redirect to a non-listed URL, Supabase falls back to the Site URL, which often still points at localhost or the preview host.

How do I explain the preview-vs-production bug to the AI agent?

Stop saying "the published site is broken" and hand it the diagnosis instead: the exact error, the failing flow, and the host difference ("login works on the preview URL and fails on domain.com; check the Supabase redirect allowlist for domain.com"). One host-specific hypothesis per prompt gets a fix; a vague symptom report gets random rewrites.

Should I check anything besides redirects before publishing?

Yes: add the production callback URL to every OAuth provider (Google, GitHub) in their own consoles, confirm production environment variables at build time, verify SPA rewrite rules so direct navigation to /dashboard doesn't 404, and test key screens in a logged-out private window so RLS policies are exercised the way real visitors hit them.