What is Row Level Security (RLS)?
Last checked 31 Aug 2026
Short answer
RLS is a Postgres feature that restricts which rows a query can see or change, enforced per-row on the database itself rather than trusted to your app's code.
The core idea
Row Level Security (RLS) is a Postgres feature, used by both Lovable Cloud and Supabase, that filters rows rather than whole tables. Instead of an app deciding what data to show, the database itself checks a policy on every query and only returns or accepts rows that pass it.
This matters because your front-end code is never trustworthy on its own — anyone can open dev tools and call your database's API directly. RLS is the actual security boundary; the UI is not.
How it works
- RLS is enabled per table.
- Once enabled, all access is denied by default unless a policy explicitly allows it.
- A policy is a rule like "authenticated users can SELECT rows where
user_id = auth.uid()". - You can have separate policies for SELECT, INSERT, UPDATE and DELETE, and different policies per role (anonymous vs authenticated vs a custom role).
A simple example
create policy "Users see their own orders"
on orders for select
to authenticated
using (auth.uid() = user_id);
This says: authenticated users can read rows from orders, but only ones where the row's user_id matches their own ID.
Why roles need their own table
For anything role-based (admin, moderator, etc.), store roles in a separate user_roles table rather than a column on profiles. A role column on a user's own row can, depending on your policies, end up editable by the user themselves — a serious privilege-escalation risk. A separate table with its own RLS lets you control who can grant or read roles independently.
What usually goes wrong
- Assuming the app's UI hiding a button is enough protection — it isn't, since the underlying query is still reachable.
- Turning RLS off to unblock development and forgetting to turn it back on before publishing.
- Writing a policy that's too broad (
using (true)) just to stop errors, which defeats the purpose.
For related setup questions see /questions/do-i-need-rls-on-my-lovable-app and /questions/how-do-i-fix-rls-errors.
Sources
Was this answer helpful?
Related questions
- AnswerHow do I back up my Lovable database?Lovable Cloud stores backups you can restore from directly in the Database screen; for extra safety, also ask Lovable to export your data periodically.
- AnswerHow do I connect Supabase to Lovable?In your Lovable project, open the Supabase integration and authorise Lovable to connect to an existing Supabase project (or create a new one), then Lovable can read and write to it the same way it does with Lovable Cloud.
- AnswerHow do I safely store API keys?Store keys as secrets in your backend (Lovable Cloud/Supabase) and call the third-party API from a server/edge function — never put keys in front-end code.
- AnswerHow do I view my database data?Open the Cloud tab (or ask Lovable) to browse tables, edit rows and run SQL directly inside your project — no separate Supabase login needed.