Row-level security (RLS)
Row-level security is a database feature that restricts, per user, which rows a query may return, insert, update or delete, on top of the ordinary table privileges. In PostgreSQL a table with row security enabled and no policy shows nobody anything, and Meadowstack uses it in its Supabase example so the database enforces the same rules as the interface.
By Bohuslav PoláčekChecked
-- The signed-in person's role. Security definer so the policies below can
-- read it without the profiles policies calling themselves.
create function public.app_role() returns text
language sql stable security definer set search_path = ''
as $$ select role from public.profiles where id = auth.uid() $$;
create function public.app_name() returns text
language sql stable security definer set search_path = ''
as $$ select name from public.profiles where id = auth.uid() $$;
alter table public.profiles enable row level security;
-- Everyone signed in sees the team (names in the history, the team page).
create policy profiles_select on public.profiles for select
using (auth.uid() is not null);
-- canWorkspace "team.role": an admin changes other people's roles, never their own.
create policy profiles_update on public.profiles for update
using (public.app_role() = 'admin' and id <> auth.uid())
with check (public.app_role() = 'admin' and id <> auth.uid());Why it matters in a business app
An app built quickly, by a person or a coding tool, tends to check permissions where it was asked to: on the button. The api then answers anyone who calls it directly. Row-level security puts the rule next to the data, so a forgotten check in the api returns nothing instead of another person's records.
It is only as good as the role the api connects with. PostgreSQL's documentation is explicit: superusers and roles with BYPASSRLS always bypass it, and a table's owner does too unless the table has FORCE ROW LEVEL SECURITY.
How Meadowstack handles it
Meadowstack 2.1 is the front end, so it cannot switch RLS on for you. What it gives you:
- The rules in one place to copy from.
domain/permissions.tsin each module (ABAC and RBAC rules together), anddocs/recipes/permissions.mdwith a sketch for PostgreSQL. - A worked example.
docs/recipes/examples/supabase/0001_requests.sqlmirrors the starter'scanForandcanWorkspaceas policies, adds a trigger for the moves a policy cannot see (a policy cannot compare the old row with the new one) and writes the history in the same transaction. It is marked as an example to adapt, not shipped code, and nothing in the framework runs migrations. - The checklist.
docs/security.mdasks before go-live that the api's database role is bound by RLS and that a test tries the forbidden calls directly.
Meadowstack 3.0, coming as an update to every licence, generates the database's row-level policies from one policy file. See also Supabase for business apps.
Common mistakes
- The api connects as the owner or a superuser. The policies exist and apply to nobody.
- RLS on, no policy, and a panic. Default deny is the point: add the policies, do not switch it off.
- Only
using, nowith check.usingfilters the rows a command may touch;with checkdecides what it may write. A policy with onlyusingreuses it for writes, which is not always what you meant. - A policy that calls a table with its own policy. The example reads the role through a
security definerfunction so the profiles' policy does not call itself.
Forced on the table that matters
alter table public.requests enable row level security;
alter table public.requests force row level security;
-- Not forced on the history: the history trigger below writes it as the
-- table's owner, and people only ever get the two policies further down.
alter table public.request_events enable row level security;Sources
Questions
Does row-level security replace permission checks in the api?
No. The api still checks, so it can answer with a clear reason; RLS is the layer that holds when the api forgets. The starter's simulated api asks the same can() before every change for that reason.
Why can my admin script see every row?
Superusers and roles with BYPASSRLS always bypass row security, and a table's owner bypasses it unless the table forces it. Connect the app with a role that is bound by the policies.
Does Meadowstack work without Supabase?
Yes. The rules are plain TypeScript and any backend can enforce them; the Supabase file is one worked example, and the permissions recipe sketches the same for any PostgreSQL.
Two ways
Build it yourself, or have it built
Build it yourself
Build your app on the framework
Get the codebase these apps stand on and build yours with Claude Code, Cursor or Codex.
One payment, lifetime updates
Get the frameworkHave it built
Have us build your app
Tell us how your team works. We plan the app with you and build it on the same framework at a fixed price.
After launch, Care keeps it improving, from €99 a month.
from €1,990
Describe your app