Back to articles

Building with AI

Lovable Supabase RLS: Empty Data or Error 42501 Fix

Fix Lovable Supabase empty lists and error 42501 by writing correct RLS policies instead of disabling security, then verify with two accounts.

LovableSupabaseRLSError 42501Database Security
Founden Team
Founden Team
•

9 min read

Already have a working prototype?
Pick a workflow to keep and one thing that needs to work before launch. Scope your first release in Founden.

Last checked against the vendors' documentation on 28 November 2026. Supabase and Lovable change their dashboards often, so if a menu name differs, search the page for the term in bold.

Your Lovable app works when you test it. Then a real user signs in and sees an empty list, or presses save and gets an error with code 42501. The rows are in the database. The app can read nothing, or write nothing, for anyone but you.

That is almost always Row Level Security (RLS) doing exactly what it was told. This guide separates the three things it can be, shows how to read each from the symptom, and ends with a prompt that asks Lovable to fix the policies without opening the data to everyone.

Why a working app suddenly shows nothing

RLS is the database rule that decides which rows each request may see or change. Supabase's documentation is direct about the default: once RLS is enabled, no data is accessible through the API when using a publishable key until you create policies - Supabase Row Level Security. Your own tests can look fine because of how you test: a request made with a server-side secret key skips RLS, and you may be testing as the one account that owns every row. Supabase says a secret key bypasses RLS only when the request has no user access token, and that it must never be used in the browser - Supabase Row Level Security.

There is a second danger on the opposite side, and it shapes how you fix the first. A table in an exposed schema without RLS is readable and writable by any role with a grant, and Lovable's own documentation warns that missing RLS policies are the most common way app data gets exposed, advising that before going live every table has policies restricting who can read and write each row - Lovable Supabase docs. So the fix for an empty list is never to switch RLS off. It is to write the right policy.

Step 1: Read the symptom

Supabase documents what each denial looks like - Supabase Row Level Security:

Symptom in your appWhat happenedGo to
A list comes back empty, no errorA policy's using condition filtered every row out. It "raises nothing, matches zero rows"Step 2
A save or delete does nothing, no errorThe same filter matched zero rows, so nothing changedStep 2
Insert or update fails with 42501Either a with check condition rejected the new row, or a grant is missingStep 3
Works for you, empty for othersThe policy compares against the wrong thing, or you are the only row ownerStep 4
Works for a table, wrong for a viewViews bypass RLS by defaultStep 5

One detail changes how you test. Supabase warns that a write test passing with no error proves nothing, because it also passes when the write matched zero rows. Check the result of the write, not the absence of an error - Supabase Row Level Security.

Step 2: The list is empty and there is no error

A select policy's using clause decides which existing rows an operation can see or act on. For update it decides which existing rows can be updated, and it also applies to delete - Supabase Row Level Security. The standard pattern for rows owned by one user is:

create policy "Users can view their own profile."
on profiles for select
to authenticated
using ( (select auth.uid()) = user_id );

That example is from Supabase's documentation. Check four things in your own policy.

The role. anon is an unauthenticated request and authenticated is a signed-in one. A policy with no to clause applies to public, a role every role belongs to, including anon, and Supabase advises always naming the role - Supabase Row Level Security. A policy written to authenticated returns nothing to a visitor whose session has not loaded yet, so a list can flash empty before it fills.

The column. user_id must hold the signed-in user's id. If your app stores the owner under another column, or stores an email instead of the id, the comparison never matches and the list is empty for everyone, including you if you test as a different account than the one that created the rows.

A null user. Supabase warns that auth.uid() returns null when the token has no sub claim, and that an or auth.uid() is null branch exposes every row. When the list is empty it is tempting to add exactly that branch. Do not. It turns an empty list into a public one.

A missing policy for the operation. Policies are written per operation. A table can have a select policy and no update policy, so reading works and saving silently changes nothing.

Step 3: Saves fail with 42501

Two different problems raise the same code, so tell them apart.

A missing grant. Supabase states that a missing grant raises a 42501 error before any policy runs, and its advice is to check the grants before changing the policy when a request fails that your policy should allow. Grant only what each role needs - Supabase Row Level Security:

revoke all on table public.reports from anon, authenticated;
grant select, insert, update, delete on table public.reports to authenticated;

A with check violation. An insert is judged by with check, which ensures any new row adheres to the policy, and for an update with check decides what the resulting row is allowed to look like. Supabase's table lists a failed with check as raising 42501 as well - Supabase Row Level Security. One cause to check is an insert that does not set the owner column, so the new row has a user_id that is not the signed-in user's. Make the app set the owner, or set it with a default, and write the insert policy as:

create policy "Users can insert their own rows."
on reports for insert
to authenticated
with check ( (select auth.uid()) = user_id );

This follows the same pattern as the documented select policy, using with check because an insert has no existing row to filter.

Step 4: It works for you but not for other users

If you are the only user who ever sees data, look for these:

  • The rows were created by a script, an import, or the Table Editor, so their user_id is empty or belongs to nobody who can sign in.
  • A policy compares to a role or claim that your own account has and theirs does not.
  • The data is shared by design, such as a team's projects, but the policy only allows the creator. Lovable's documentation says to design your schema and policies with shared data in mind when a database is shared - Lovable Supabase docs.

Test with two real accounts, not one. Sign in as user A, create a row, then sign in as user B and confirm B sees none of A's rows and cannot change them.

Step 5: Views bypass the rules

Supabase says views bypass RLS by default because they are usually created with the postgres user. On Postgres 15 and above you make a view obey the policies of its underlying tables with security_invoker - Supabase Row Level Security:

create view <VIEW_NAME>
with(security_invoker = true)
as select <QUERY>

A view that returns every user's rows is a leak. A view that returns nothing after you add security_invoker points at the policy beneath it, so fix the policy, not the view.

Step 6: Test the policy as the user, not as the owner

Supabase documents pgTAP tests that switch identity inside a test, and runs them with supabase test db:

set local role authenticated;
set local request.jwt.claim.sub = '11111111-1111-1111-1111-111111111111';

The same page tells you never to prove an allowed write with a test that merely does not fail, because it passes when the write matched zero rows. Add returning to the write and assert the value - Supabase Row Level Security. If you do not run the Supabase command line, the equivalent check in the app is the two-account test above.

A note on speed

Once the policies are right, make them cheap. Supabase advises indexing every column a policy filters on, and wrapping helper calls as (select auth.uid()) so Postgres can cache the result per statement - Supabase Row Level Security. A list that is correct but takes seconds to load can be a policy filtering on an unindexed user_id.

A prompt to give Lovable

Results vary, so read what it changes against the steps above. Lovable's documentation itself suggests asking it to review your policies and then verifying them in the Supabase dashboard - Lovable Supabase docs.

Review Row Level Security on every table in my Supabase project.
- List each table, whether RLS is on, and which policies exist per operation.
- For tables where each row belongs to one user, add select, insert, update
  and delete policies for the authenticated role that compare the row's
  user_id with (select auth.uid()). Name the role in every policy.
- Use with check on insert and update, and make the app set user_id on insert.
- Do not add any branch that allows auth.uid() is null, and do not turn RLS
  off to make a list appear.
- For any view, make it use security_invoker so it follows the table policies.
- Index every column the policies filter on.
- Give me the SQL you changed and a short test I can run with two accounts.

Then sign in as two different users and confirm each sees only their own rows.

Two nearby checks belong with this one: that no secret key ever reaches the browser, covered in the security checklist for AI-built apps, and, if customers pay you through the app, that the order really gets saved, covered in Lovable Stripe webhook not working.

If you would rather hand it over

Founden wrote this guide and also sells help with this kind of launch blocker, so weigh the next paragraph accordingly.

Founden is an AI that builds and runs companies. Its finish-your-app offer opens a separate Founden project from what you can share (a public repository, a public preview, or screenshots and notes) plus one workflow to keep and one launch blocker to clear, such as the list that stays empty for real users. Building starts with Pro at $29 a month, the account is free, and your original app, hosting and database stay on your own setup. A real launch still needs your own access to your database and any payment or email service. If that fits, scope your release. If not, the steps above are the whole job.

In this topic: Building with AI

How do you build software with AI? Every guide on it

Data behind this topic: AI app builders and coding agents: free and first paid plans.