Lovable + Supabase RLS not working: why your data is empty (and how to fix it)

By AI App Medic · Updated · Lovable · Supabase · RLS

A very common Lovable + Supabase symptom: you submit a form, Lovable shows a success toast, but the list never shows the new item. Or the app suddenly starts throwing 401/403 errors after you "secured" the database. In almost every case the cause is Row Level Security (RLS) doing exactly what it was told to do.

How RLS actually behaves

Supabase exposes your Postgres tables through an API. Every request runs as a Postgres role: anon (signed-out visitor), authenticated (signed-in user) or a privileged server role. When RLS is enabled on a table, Postgres only allows an operation if a policy for that operation and role says yes:

One error that looks like RLS but is not: permission denied for table on a table you created recently. Since Supabase stopped granting new public tables to the API roles automatically, the table needs an explicit GRANT before RLS is even checked. That fix is in Supabase permission denied for table.

Each operation needs its own policy. A common AI-generated setup has an INSERT policy for the create form but no SELECT policy for the list, so the row is saved but invisible.

Step 1: find out what is really happening

  1. Open your app, open DevTools > Network, and repeat the action.
  2. Find the request to https://<project>.supabase.co/rest/v1/<table>. Note the status code and the response body.
  3. In the Supabase dashboard open SQL Editor and list the policies on that table:
select policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'public' and tablename = 'todos';

If there is no row for SELECT (or ALL), that is your empty list. If qual is true, the policy lets everyone read everything, which is a different problem (see RLS enabled but data still public).

Step 2: make sure every row has an owner

Per-user policies compare a column such as user_id with auth.uid(). If rows were inserted without user_id, they will never match. The safest pattern is to let the database fill it in:

alter table public.todos
  alter column user_id set default auth.uid();

-- rows created before the fix have no owner; inspect them
select id, created_at from public.todos where user_id is null;

Then remove any code that sends user_id from the browser, so a user cannot create rows "owned" by someone else.

Step 3: add one policy per operation

alter table public.todos enable row level security;

create policy "Owners can read"
  on public.todos for select to authenticated
  using ((select auth.uid()) = user_id);

create policy "Owners can insert"
  on public.todos for insert to authenticated
  with check ((select auth.uid()) = user_id);

create policy "Owners can update"
  on public.todos for update to authenticated
  using ((select auth.uid()) = user_id)
  with check ((select auth.uid()) = user_id);

create policy "Owners can delete"
  on public.todos for delete to authenticated
  using ((select auth.uid()) = user_id);

Notes that trip people up:

Step 4: test as a real user, not as the dashboard

Sign in to your app with two different accounts. Create data with account A, then confirm account B cannot see or change it, both in the UI and by repeating the API call from DevTools. Also test while signed out. The Table Editor is not a valid test, because it bypasses RLS. If a lookup that uses .single() fails with a 406 and code PGRST116, a missing SELECT policy is the usual reason; see JSON object requested, multiple (or no) rows returned. The same policies decide which Realtime events each user receives, so if live updates stop arriving after you tighten RLS, see Supabase Realtime not working.

When the AI keeps "fixing" it in circles

If you prompt Lovable with "fix the RLS error", it may add a broad policy such as using (true) to make the error disappear. The app works, but now every visitor can read every row. Always read the SQL migration before approving it, and look for true in using or with check. If the message is infinite recursion detected in policy, that is a cycle in the policies, not a missing one. Fix it with a security definer helper; do not disable RLS. The walkthrough is in infinite recursion detected in policy.

FAQ

Why does my Supabase query return an empty array with no error?

When Row Level Security is enabled on a table and no SELECT policy matches the current user, Postgres silently filters out every row. The API returns 200 with an empty array instead of an error.

Why can I see the rows in the Supabase Table Editor but not in my app?

The Table Editor runs with elevated privileges that bypass RLS. Your app runs as the anon or authenticated role, so it only sees rows your policies allow.

Should I just turn RLS off to make it work?

No. With RLS off, anyone who has your public anon/publishable key (which is in your JavaScript) can read and often write the whole table. Add correct policies instead.

Related guides