Unslop

Lovable + Supabase: RLS is disabled. How to fix it without breaking your app

Supabase says Row Level Security is off on tables your Lovable app uses. What that means, how to check it, and how to turn it on safely.

Updated

Short answer: with Row Level Security (RLS) off, anyone who has your app's public Supabase key can read, change or delete every row in that table. The key is in your app's JavaScript, so assume people have it. Turn RLS on and add policies before you do anything else.

Why Lovable apps end up with RLS off

Lovable talks to Supabase straight from the browser using the public (anon or publishable) key. That is a normal Supabase setup, but it is only safe when RLS decides what each user is allowed to see. Tables created by hand, by SQL pasted from a chat, or early in a project often never had RLS switched on. The app works fine, so nobody notices.

Step 1: find the tables that are open

In the Supabase dashboard, open Advisors → Security Advisor. Tables without RLS show up as errors. You can also run this in the SQL editor:

select tablename, rowsecurity
from pg_tables
where schemaname = 'public'
order by rowsecurity, tablename;

Any row with rowsecurity = false is open to the public key.

Step 2: write the policies first

Turning RLS on with no policies blocks all access through the public key, so your app will suddenly show empty screens. Decide who should see each table, then write a policy. The most common case is "users can only see and edit their own rows":

create policy "Users read own rows"
on public.projects for select
to authenticated
using ((select auth.uid()) = user_id);

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

create policy "Users update own rows"
on public.projects for update
to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);

create policy "Users delete own rows"
on public.projects for delete
to authenticated
using ((select auth.uid()) = user_id);

Replace projects and user_id with your table and the column that stores the owner's id. If a table has no owner column, that is the real problem to solve first.

Step 3: turn RLS on

alter table public.projects enable row level security;

Repeat for every table the Security Advisor flagged.

Step 4: test as two different users

  1. Sign up two test accounts in your app.
  2. Create data as user A.
  3. Log in as user B and confirm you cannot see or change A's data.
  4. Log out and confirm the app shows nothing private.

Common mistakes

  • A policy with using (true). That allows everyone and is the same as RLS off. Lovable sometimes writes these to make an error go away.
  • Using the service role key in the app to "fix" errors. That key skips RLS entirely. It must never reach the browser. See our guide on exposed keys.
  • Forgetting storage buckets. Files in Supabase Storage have their own policies. Check them too.