How it worksEngineersResultsPricingFAQBlog
Log inStart for free
How it worksEngineersResultsPricingFAQBlog
Log inStart for free
Loading…

The talent marketplace pairing AI native builders with senior software engineers.

EngineersHow it worksBlogSnapDev for your AIFix a Lovable app

© 2026 SnapDev.ai. Real engineers, on demand.

Terms of ServicePrivacy Policy
Loading…
  1. Home
  2. Guides
  3. Lovable + Supabase errors: why preview works but live doesn't

Lovable + Supabase errors: why preview works but live doesn't

Reviewed by Ali Amanat Ali, senior engineer

Last updated 24 November 2026

On this page

  1. Lovable Cloud or your own Supabase project: which one you have
  2. Preview and live connected to different projects
  3. Row Level Security: the rules that decide who can read or save data
  4. Login redirects: the Site URL and redirect URLs
  5. Keys and environment variables
  6. Paused free-tier projects
  7. Reading Supabase logs: what 401 and 403 errors mean
  8. New tables may need a GRANT
  9. When to get help
  10. Frequently asked questions

Your Lovable app works in the editor preview. Then you publish it, and something breaks. A login loops, a list comes back empty, or a save does nothing.

Lovable's docs say the preview and your published app share the same backend and the same data. So when only the live site breaks, the cause is usually something that differs between the two: the web address, who is signed in, or which version of the app is live. This guide walks through the Supabase settings behind those differences, in the order worth checking them.

Quick fix

Quick check: open your live site in a private browser window and try the broken step, so you see it as a signed-out visitor does. If sign-in fails, start with login redirects. If data is missing or a save fails, start with Row Level Security. If you changed anything since you last published, publish again first: the live site only changes when you publish.

Lovable Cloud or your own Supabase project: which one you have

A Lovable app gets its database, logins and file storage from one of two places. The first is Lovable Cloud, which Lovable's docs now call the built-in backend. It runs on Supabase's open-source foundation, and Lovable manages it for you. The second is a Supabase project you own, connected to Lovable, with its own Supabase account and billing.

It matters because the fixes live in different places. On the built-in backend, you change settings inside Lovable. On your own Supabase project, Lovable's docs say auth settings and social logins are set in the Supabase dashboard. Lovable only adds its own addresses to that project's redirect URLs.

  1. 1

    Open the More menu in your project

    On the built-in backend, the More menu has views such as Database, Users and Storage, and More → Settings has Secrets and Logs. Lovable's docs say these views only apply to the built-in backend.

  2. 2

    Look for a Supabase entry

    If you connected your own project, More → Supabase shows that Supabase project's name and status, with links to the Supabase dashboard.

Preview and live connected to different projects

Inside Lovable, the preview and the published app use one backend. Even so, a few things can leave your live site talking to a different project, or to old settings.

  1. 1

    The live site is an old snapshot

    Publishing deploys a snapshot of your project. Later changes are not pushed live until you click Publish, then Publish changes. If you connected a different Supabase project, or changed keys, after your last publish, the live site still uses the old ones. A small dot on the Publish button means you have changes that are not live yet.

  2. 2

    The app is hosted outside Lovable

    On your own host, you set the Supabase values yourself, such as VITE_SUPABASE_URL and VITE_SUPABASE_PUBLISHABLE_KEY. Lovable's docs say these are built into the app at build time, so after changing them you must rebuild and redeploy. If the host holds values from another project, your live site reads and writes a different database.

  3. 3

    You remixed the project

    A remix of a built-in backend project gets a new backend with fresh keys. Its tables are copied without their data, no users are copied, and secrets you added by hand must be entered again.

  4. 4

    Two Lovable projects share one Supabase project

    Lovable allows this but warns you. The projects read and write the same data and overwrite each other's secrets, including LOVABLE_API_KEY, so features that use that key stop working.

To check, compare the Supabase project URL in your project's .env file with the one your live site was built with.

Row Level Security: the rules that decide who can read or save data

Row Level Security, or RLS, is a set of rules inside your database. Each rule decides which rows a user can see or change. Lovable's own example is "users can only read their own orders". Lovable sets up these rules automatically when it builds features that store user data.

Before the rules there is a second check, called a grant. Supabase's docs put it simply: grants decide whether a role can use a table at all, and rules decide which rows. Requests from your app's pages arrive as one of two roles: anon for visitors who are not signed in, and authenticated for signed-in users. Server code can also use service_role, which skips RLS.

A rule that blocks something shows up in one of two ways:

A blocked read looks like missing data. There is no error. The database quietly leaves out the rows the rule filters, so the page just shows nothing.

A blocked save shows an error. When a user tries to add or change a row the rules don't allow, the database returns error 42501. Supabase's docs say apps often report it as a 401 or 403.

Why preview and live can differ here: you usually test while signed in, often as the account that created the data. Your visitors may be signed out, or signed in as someone else. The same rule gives them a different answer.

  1. 1

    Read the rules

    On the built-in backend, go to More → Database, select Manage, then Policies. Each rule shows its command (SELECT reads, INSERT adds, UPDATE changes, DELETE removes) and who it applies to. This view is read-only.

  2. 2

    Ask Lovable to change a rule

    Describe the rule in plain words in the project chat. Lovable's docs give this example: "Only allow users to see their own invoices."

  3. 3

    On your own Supabase project, check in Supabase too

    Lovable's docs ask you to verify your rules yourself in the Supabase dashboard as well as asking Lovable to review them.

  4. 4

    Check the grant before the rule

    Supabase's docs say a missing grant also returns 42501, with a hint naming the grant you need. So if a request fails that your rule should allow, check the grants first. The section on new tables below covers the most likely cause.

Warning

Don't fix a blocked read by switching RLS off. Supabase warns that a table without RLS can be read and written by any role with a grant on it, which can include visitors who are not signed in. Lovable's docs call missing RLS policies the most common way app data gets exposed.

Login redirects: the Site URL and redirect URLs

After someone signs in, confirms their email or resets a password, Supabase sends them back to your app. Two settings decide where.

  1. 1

    Site URL

    The default address users return to when the app doesn't name one. Supabase's docs say this setting is critical for email confirmations and password resets, and that you should change it from http://localhost:3000 to your live address.

  2. 2

    Redirect URLs

    The list of addresses Supabase is allowed to send users back to. The address your app asks for has to match an entry on this list.

Lovable's docs are direct about this: if sign-in works in preview but breaks on your published app or custom domain, these URLs are usually the reason.

On the built-in backend: Lovable keeps both settings up to date. When you publish, it sets the Site URL to your published address, unless the Site URL is already on your own domain. When you connect a custom domain, it adds that domain to the redirect URLs. If sign-in still fails, ask Lovable in the project chat to add your domain, or add it under More → Users → Settings → Advanced → Redirect URLs.

On your own Supabase project: Lovable adds its own addresses to the redirect URLs, but the Site URL and any other address are yours to set. In the Supabase dashboard, open Authentication, then URL Configuration. Set the Site URL to your live address, and add every address people sign in from to the redirect URLs.

Google sign-in with your own credentials: the live domain also needs a redirect URI in Google Cloud Console. Lovable's docs say these must match exactly, down to the scheme, domain, path and trailing slash. Until they do, Google sign-in fails with a redirect URI mismatch error.

Warning

Supabase allows wildcards such as ** in redirect URLs, which helps with preview links. For your live site, Supabase recommends the exact address instead.

If sign-in broke when you moved to your own domain, see why a Lovable custom domain stops working.

Keys and environment variables

Your app uses two kinds of values to reach Supabase and other services. They live in different places.

  1. 1

    Browser values go in .env

    Values that start with VITE_, such as VITE_SUPABASE_URL and VITE_SUPABASE_PUBLISHABLE_KEY, are built into the app and are safe to be public. They live in the .env file in Lovable's code editor or your synced repository. Lovable needs that file in the repository, so don't add it to .gitignore: Lovable's docs say that breaks the preview.

  2. 2

    Private values go in Secrets

    Keys for services like Stripe or Resend belong in Secrets, which only your backend functions can read. On the built-in backend, go to More → Settings → Secrets. Names starting with SUPABASE_ are filled in by Lovable, so you don't add those. On your own Supabase project, secrets are managed in Supabase.

  3. 3

    Use the right Supabase key

    The publishable key, which starts with sb_publishable_, is meant for the browser and only reaches what your RLS rules allow. The secret key, which starts with sb_secret_, skips every RLS rule and must stay on the server. Supabase says a secret key used in a browser gets a 401 Unauthorized. The older anon and service_role keys are the legacy versions, which Supabase is deprecating by the end of 2026. A long key starting with eyJ is a legacy key.

  4. 4

    Find the right values

    In the Supabase dashboard, every key is under Settings > API Keys. The Connect dialog shows your project URL and publishable key, ready to paste.

Warning

Never put a secret key or a service_role key in a VITE_ variable. Those values ship to every visitor's browser, and these keys skip all of your security rules.

Paused free-tier projects

A paused backend stops the live app even when nothing in your code is wrong. Both kinds of backend can pause.

Your own Supabase project on the Free plan: Supabase pauses Free plan projects that get too little database activity over 7 days. You get a warning email about a week before, and another once it happens. Requests to a paused project return status 540. Projects on paid plans are not paused.

  1. 1

    Open the Supabase Dashboard

    Select the organization, then the paused project.

  2. 2

    Click Resume project and confirm

    The project comes back with its data and settings. You can restore a paused project for up to 1 year after it was paused.

The built-in backend: Lovable pauses a project's backend after about 7 days without activity. While it is paused, your published app can't read or save data, sign users in or serve files, and visits to the live app don't wake it. Opening the project in the editor wakes a project paused for inactivity. Otherwise, use the paused card in the Database, Users or Storage view and click Wake up. If you ran out of credits, top up first. Waking up takes a few minutes.

Reading Supabase logs: what 401 and 403 errors mean

The logs show which request failed and why. Where you find them depends on your backend.

  1. 1

    On the built-in backend

    Go to More → Settings → Logs. Pick a log type, set the time range, and use the status filter to show only errors. The logs don't update live, so click Refresh for new entries. You can copy an entry and paste it into the project chat for Lovable to fix.

  2. 2

    On your own Supabase project

    Open Logs in the Supabase dashboard and pick a log type such as API Gateway, Postgres, Auth or PostgREST. The Status filter matches an HTTP status or a Postgres error code.

Then read the status code:

401 Unauthorized. Supabase didn't accept the request as coming from someone allowed in. A permission error (42501) from a visitor who is not signed in comes back as 401. So does a login token that couldn't be read, and a secret key used in a browser.

403 Forbidden. The user is signed in but isn't allowed to do this. Supabase returns the same 42501 permission error as 403 when the request is signed in. Check the table's grant first, then the RLS rule for that action.

200 with no data. Not an error at all. This is usually an RLS rule hiding the rows.

540. The project is paused. See the section above.

A missing-grant error, as Supabase's changelog shows it
{
  "code": "42501",
  "message": "permission denied for table your_table",
  "hint": "Grant the required privileges to the current role with: GRANT SELECT ON public.your_table TO anon;"
}

New tables may need a GRANT

This one is recent. Supabase announced it in its changelog on 28 April 2026 as "Breaking Change: Tables not exposed to Data and GraphQL API automatically". New Supabase projects got the new default from 30 May 2026, rolled out over a few weeks. Supabase scheduled it for all existing projects from 30 October 2026.

What changed: a new table in the public schema can't be reached by your app until you grant access to it. Tables you already had keep their grants and keep working, and RLS works as before.

The symptom is a 42501 error on a table you just added, with the message permission denied for table and the table's name. Adding an RLS rule won't fix it, because the grant check comes first.

Supabase's example grants for a new table (replace your_table)
grant select on public.your_table to anon;
grant select, insert, update, delete on public.your_table to authenticated;
grant select, insert, update, delete on public.your_table to service_role;

Give each role only what it needs. Grant anon access only to data that signed-out visitors should see. Supabase recommends turning on RLS and adding rules for the table in the same step.

Warning

A grant makes a table reachable from the browser. Make sure RLS is on and the table has rules before you add one.

Lovable's docs and changelog don't mention this change. They don't say whether Lovable adds these grants when it creates a table for you, or whether the change reaches the built-in backend.

When to get help

Get help when you've worked through these checks and the live site still breaks. Get it sooner if the fix means changing security rules on real customer data, or if the logs show an error you can't place.

With SnapDev, you get a vetted senior engineer in minutes. Share your screen and leave with it fixed. Engineers work in your own repository, and if the engineer can't solve it, your hours go back to your account. See how it works on fix your Lovable app.

Frequently asked questions

Why does my Lovable app work in preview but not when it's published?

The preview and the published app share one backend, so the difference is usually in the settings around it. The common causes are login redirect URLs that don't include your live address, RLS rules that answer visitors differently from you, a live site that hasn't been published again since your last change, and, if you host outside Lovable, keys that point at another project.

Is it safe that my Supabase key is visible in my app's code?

Yes, if it is the publishable key or the legacy anon key. Supabase designed it to be public, and it only reaches what your RLS rules allow. A secret key or service_role key must never be in your app's code.

Why does my app show an empty list instead of an error?

That is usually RLS. When a rule filters rows out of a read, the database returns no rows and no error. Check the reading rule for that table, and who it applies to.

Do I need to add GRANTs to my old tables after 30 October 2026?

No. Supabase says existing tables keep their grants and stay reachable. Only new tables in the public schema need an explicit grant.

My Supabase project was paused. Did I lose my data?

No. Supabase says a paused project keeps its data and settings, and you can restore it from the dashboard for up to 1 year. On Lovable's built-in backend, pausing keeps your data in place too.

Still stuck? Talk to a senior engineer in minutes

Tell us where you're stuck and we match you with a vetted senior engineer who takes it from there.

Get matched with an engineerMore help with Lovable