Skip to content

Patterns

Permissions

In Meadowstack every rule about who may do what lives in one file per module, `domain/permissions.ts`, and screens ask it with the record, `can("job.read", job)`, through `<Can>`, `usePermission` or `useCan`, never by comparing roles. The api asks the same function before every change and a real backend enforces it again with Postgres row-level security, so a role changes the data a person sees, not only the menu.

By Bohuslav PoláčekChecked

apps/demo/src/modules/print/domain/permissions.ts
const rules: Record<string, string[]> = {
  "job.read": ["sales", "manager", "prepress", "press", "customer"],
  // The shop's insides: a colleague's proof check, the machine plan, internal steps in the history.
  "job.internal": ["sales", "manager", "prepress", "press"],
  "job.create": ["sales", "manager"],
  // The assistant's draft of a job from an enquiry, with its calculation (Foldline's AI moment): the approver signs
  // the price off as the second pair of eyes, customer care sends it.
  "job.draft": ["sales", "manager"],
  "job.advance": ["sales", "manager", "press"],
  "job.edit": ["sales", "manager"],
  "job.cancel": ["sales", "manager"],
  // A note in the history is the shop's own: a customer does not see it.
  "job.note": ["sales", "manager", "prepress", "press"],
  "proof.request": ["sales", "manager"],
  "file.check": ["prepress", "manager"],
  "proof.make": ["prepress", "manager"],
  "proof.check": ["prepress", "manager"],
  "proof.decide": ["customer", "sales", "manager"],
  "mail.read": ["sales", "manager", "prepress"],
  "mail.send": ["sales", "manager", "prepress"],
  "machine.read": ["sales", "manager", "prepress", "press"],
  "machine.plan": ["manager"],
  "machine.done": ["press", "manager"],
};
The print shop's rules in the demo: one table of actions by role, where a customer may read jobs and decide on proofs and nothing else. The function under it narrows each action by the record. Read from the repository when the site was built.

Open it in the live demo

The flow, step by step

The demo's print shop, as a customer meets it: she signs in to approve the proofs of her own jobs.

  1. Sign in. Her role is customer. The table above lets a customer read jobs and decide on proofs, and nothing else: no mailbox, no machines, no quotes.
  2. Her jobs only. Another customer's job does not exist for her. The rule is not a filter in a page: job.read with a job answers yes only when the job's customer is her (ownJob), and the api filters by the same rule.
  3. A proof. A proof the shop sent her she can approve or return. On anything else the actions are not there at all, hidden rather than greyed out.
  4. The history. The job's history shows her side of it, from the quote to the delivery. The shop's notes and internal steps, such as a colleague's check of the proof, never reach her.
  5. Inside the shop. The prepress operator who made a proof cannot check it: proof.check needs a proof someone else made. Only the production manager plans the machines; everyone else in the shop reads the plan.
  6. A page she may not open. It shows NoAccess under its header, so she knows the page exists and is closed to her, never a blank screen.
  7. A request sent by hand. The api asks the same function and refuses it. In the starter, the sentence is "You don't have permission to do that.", and with a real database the row-level security policies refuse it again.

The rules and where each one is enforced

Roles changing the data came from a finding. The audit of 25 Oct 2026 in the demo's construction company found that the client's supervisor could see "Cost against plan" and other sites in the "What changed" and "Lately" lists. Now site.costs, the company's cost against its plan, is an action no external role has, and a screen, a feed, the bell and the assistant all ask site.read with the site.

What AI coding tools build instead

  • if (user.role === "approver") in a component. The rule is copied into every screen that needs it and drifts, and a new role means a hunt through the code. Here the component asks can("request.approve", request).
  • A hidden button the api trusts. The page hides it, the endpoint accepts the request from anyone who sends it. Here the api asks the same function, and the database asks again.
  • A disabled button with no reason. People cannot tell whether they lack the right, the data or the timing. Hide it, or say who decides.
  • A page that renders nothing for a role without access, or a silent redirect to the start. NoAccess says the page exists and is closed.
  • Roles that change only the menu. The customer cannot open the costs page, but the dashboard widget, the activity feed and the bell still show internal margins and other clients.
  • A backend that connects as the table's owner, or with a key that bypasses row-level security, so every policy is skipped without a sound.

Where to see it

Example apps with pages some roles may not open

Which example apps and modules render the kit's NoAccess, computed from the demo's code when the site was built.Read from the demo's source when the site was built: 9 of 9 example apps render <NoAccess>, in the modules named here as each app's sidebar names them.

The same rules in Postgres

docs/recipes/examples/supabase/0001_requests.sql
-- canFor "request.read": a draft is private to its author and the admins.
-- A row this hides is "not found" to the api, the way the simulated api answers.
create policy requests_select on public.requests for select
  using (status <> 'draft' or requester_id = auth.uid() or public.app_role() = 'admin');

-- canFor "request.create": everyone with a role asks, as themselves, as a draft.
create policy requests_insert on public.requests for insert
  with check (public.app_role() is not null and requester_id = auth.uid() and status = 'draft');
The starter's Supabase example: the read and create rules of its permissions file as row-level security policies, so a query that skips the screens still gets only what the person may see.

Questions

Is hiding a button enough to protect an action?

No. Hiding keeps the screen honest, but the api asks the same rules before every change, and with a real database the row-level security policies refuse it again. A request sent by hand gets the same answer as the screen would.

Should a button someone cannot use be hidden or disabled?

Hidden. A disabled button with no reason leaves people guessing. The exception is a bulk bar, where a disabled button with a tooltip says why none of the selected rows qualify, and a decision that belongs to someone else names who decides.

Where do the permission rules live?

In one file per module, domain/permissions.ts: a table of actions by role, then conditions on the record, such as a draft being private to its author. The screens, the api and the tests all call the same function.

Can a customer or another external role see internal costs?

No. An external role never sees internal costs, margins or other clients' records, in widgets, feeds, notifications, search results and assistant answers as on the pages, because each of them asks with the record instead of checking the menu.

Do I need row-level security if the api already checks?

It is the second lock. The starter's Supabase example writes the same rules as policies, so a query that skips the api still gets only the rows the person may see. Check that the api does not connect as a role that bypasses them.

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 framework
  • Have 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