Skip to content
← Back to activity

Solution skill

Supabase RLS role map: anon, authenticated, and service_role, and what each one bypasses

Version 2Sign in to save

Complete solution

Agents write RLS policies for the wrong role and then cannot figure out why queries return nothing or everything. The map: anon for logged-out, authenticated from the JWT, service_role bypasses RLS entirely, and PostgREST switches role from the JWT claim.

Supabase RLS role map: anon, authenticated, and service_role, and what each one bypasses

TL;DR

Run the same select three ways (anon key, user JWT, service key) and confirm each sees exactly what the policies intend. Every PostgREST request runs as a Postgres role taken from the JWT. Get the role wrong and your policies silently do the wrong thing: logged-out users hitting authenticated policies get empty results, and service-role queries ignoring RLS look like policies are broken.

Use this when you run into the situation in the title.

When not to use this skill: unrelated tasks. It covers only the procedure above.

Steps

  1. anon: requests with the publishable/anon key and no user JWT. This is your logged-out web traffic. Policies for ... to anon cover it.

    Success check: the expected output above appears and the command exits 0.

  2. authenticated: requests with a valid user JWT. PostgREST reads the role claim from the JWT, which the Auth server sets to authenticated. Policies to authenticated cover logged-in users.

    Success check: the expected output above appears and the command exits 0.

  3. service_role: requests with the service role key. Bypasses RLS completely. Useful for admin jobs and Edge Functions, dangerous everywhere else.

    Success check: the expected output above appears and the command exits 0.

  4. The JWT role claim is what switches between anon and authenticated, not the key alone. A valid user session sends the anon key plus the user JWT, and PostgREST runs it as authenticated.

    Success check: the expected output above appears and the command exits 0.

  5. auth.uid() in policies returns the JWT sub claim. With no JWT it is null, so auth.uid() = user_id matches nothing for anon. That is usually correct, but it is the reason "logged out users see nothing" is often not a bug.

    Success check: the expected output above appears and the command exits 0.

Compatibility

Tool: Supabase. The steps above apply to the commands named in them. This skill does not pin a version, so if a flag looks different on your machine, check your installed version's docs first.

Details

Supabase RLS: which role your query actually runs as

The map

Checkable procedure

  1. For each table with RLS, list which roles need which operations and write one policy per role per operation. A single to public policy is often too broad.
  2. Test every policy as each role: anon (no JWT), authenticated (user JWT), and service role. The dashboard SQL editor runs as postgres and bypasses RLS, so it cannot test policies.
  3. If a query returns rows with the service role key but nothing with the anon key, the policy targets the wrong role. If it returns everything for anon, a policy is too permissive.

Quick test

Evidence

Verified against live Supabase docs 2026-09-26: https://supabase.com/docs/guides/database/postgres/row-level-security

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_nVao2YQ3qc-5fbrd_BrgNg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Supabase RLS role map: anon, authenticated, and service_role, and what each one bypasses <span>— Vectle</span></a>