Skip to content

ericrisco/rsc-harness / skills/supabase

supabase

Verified

Use when building on Supabase as a backend over managed Postgres — wiring the supabase-js or SSR client, writing or debugging Row Level Security, cookie-based Auth, Storage buckets, Realtime, and Edge Functions, including local versus server JWT verification and the service-role key. NOT raw Postgres tuning (that is `postgresdb`).

FileKindSize
SKILL.mdskill md13.7 KB
evals/README.mdmarkdown923 B
evals/cases.yamlconfig3.1 KB
references/auth-ssr.mdmarkdown6.0 KB
references/rls-cookbook.mdmarkdown3.7 KB
scripts/verify.shexecutablescript6.1 KB

references/rls-cookbook.md

View on GitHub
# RLS cookbook

Concrete Row Level Security patterns. Every policy assumes RLS is enabled on the table
(`alter table X enable row level security;`) and is scoped `to authenticated` unless a public-read case
explicitly needs `anon`. Always pair owner/tenant predicates with an index on the filtered column.

## Owner-only (per-user rows)

```sql
alter table documents enable row level security;

create policy "owner full access" on documents
  for all to authenticated
  using ( user_id = (select auth.uid()) )
  with check ( user_id = (select auth.uid()) );

create index on documents (user_id);
```

`using` gates which rows are *visible* (select/update/delete); `with check` gates what *new/updated*
rows are allowed (insert/update). Set both or an update can move a row out of your reach.

## Multi-tenant (team_id via membership table)

Don't inline a correlated subquery against the membership table in every policy — it re-runs per row.
Use a `security definer` helper that runs once and is safe to index against.

```sql
create table memberships (
  user_id uuid not null references auth.users (id),
  team_id uuid not null references teams (id),
  primary key (user_id, team_id)
);

-- security definer: runs with the function owner's rights, bypassing RLS on memberships,
-- so the helper itself doesn't recurse. Lock down its search_path.
create or replace function is_team_member(target_team uuid)
returns boolean
language sql
security definer
set search_path = ''
stable
as $$
  select exists (
    select 1 from public.memberships m
    where m.team_id = target_team
      and m.user_id = (select auth.uid())
  );
$$;

create policy "team members read" on projects
  for select to authenticated
  using ( is_team_member(team_id) );

create index on projects (team_id);
create index on memberships (user_id, team_id);
```

## Public-read, private-write

```sql
-- anyone (even anon) may read published rows
create policy "public reads published" on posts
  for select to anon, authenticated
  using ( status = 'published' );

-- only the author may write
create policy "author writes" on posts
  for all to authenticated
  using ( author_id = (select auth.uid()) )
  with check ( author_id = (select auth.uid()) );
```

## Storage object policies

`storage.objects` is a normal table; policy it the same way. Convention: prefix paths with the owner id
so the policy can parse it.

```sql
create policy "users manage own avatar folder" on storage.objects
  for all to authenticated
  using (
    bucket_id = 'avatars'
    and (storage.foldername(name))[1] = (select auth.uid())::text
  )
  with check (
    bucket_id = 'avatars'
    and (storage.foldername(name))[1] = (select auth.uid())::text
  );
```

## Realtime private channel (realtime.messages)

Private Broadcast/Presence channels are authorized by RLS on `realtime.messages`. The channel name is
available as `realtime.topic()`.

```sql
create policy "members read room broadcasts" on realtime.messages
  for select to authenticated
  using ( is_team_member( (realtime.topic())::uuid ) );

create policy "members write room broadcasts" on realtime.messages
  for insert to authenticated
  with check ( is_team_member( (realtime.topic())::uuid ) );
```

## Testing a policy locally

Simulate an authenticated request inside `psql` / a migration test by switching role and faking the JWT
claims that `auth.uid()` reads.

```sql
begin;
  set local role authenticated;
  set local request.jwt.claims = '{"sub":"00000000-0000-0000-0000-000000000001"}';

  -- auth.uid() now returns that sub; run the query you expect a user to make
  select * from documents;        -- should return only that user's rows
rollback;
```

Reset with `reset role;`. Run the same query as `anon` to confirm it returns nothing where it should.
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall