Row level security (RLS) policies
Row level security (RLS) controls which data users can access across your database, storage, and realtime features, the live updates your app pushes to users. A policy is a rule that decides which rows a signed-in user can see or change, for example “users can only read their own orders”. Lovable sets up these rules automatically when it builds features that store user data, so that one user’s private data is not served to another. To review the rules, go to More → Database, select Manage, then Policies. The policies view lists each policy with:- Policy name: what the rule is for.
- Command: the action the rule applies to. SELECT is reading data, INSERT is adding it, UPDATE is changing it, and DELETE is removing it.
- Applies to: which users the rule covers, such as signed-in (authenticated) or anonymous (anon) users. See Who a policy applies to.
- Rule expression: whether the rule has a condition. Expand the row to read the SQL condition that must be true for the action to be allowed.
Who a policy applies to
Every request your app sends to your database comes in as one of three database roles. A database role is the identity a request uses. Each policy names the roles it covers and what those roles can read or change. The Applies to column in the policies view shows the roles for each policy.anon: a request from someone who is not signed in, such as a visitor on a public page.authenticated: a request from someone signed in to your app.service_role: privileged access for your app’s server code. Your RLS policies do not apply toservice_rolerequests.
anon, or as authenticated after someone signs in, so your policies still apply to them.
A role shows only whether someone is signed in, not who the person is or whether they are an admin of your app. If a policy checks only for authenticated, every signed-in user gets the same access to every row that policy covers.
To keep one user’s data from another, a policy has to compare the person making the request with something in the row, such as the row’s owner. For example, a policy that checks the row’s owner shows each user only their own orders.
Your policies do not apply to service_role, so server code that uses service_role must check permissions itself. Ask Lovable in the project chat whether your app’s server code checks permissions. See Database security with RLS.
To review what each role can reach, ask Lovable in the project chat, for example: