When someone signs in, Supabase knows who is asking for a note. Row Level Security (RLS) lets you set rules for which notes that person can read or change. Here you’ll give each note one owner and check that two signed-in accounts can each work with their own notes.
Use a disposable copy of your app and its own Supabase project. Before you run SQL or create accounts, check that the URL in your test app matches the test project and that you opened that project’s SQL editor. Use made-up notes. If signing up sends a message, make sure it can reach only a test inbox or address you control. If you can’t verify the setup, stop before making changes.
Understand the access layers
The browser uses your project’s publishable key to connect to Supabase. Once someone signs in, the app also sends that person’s session with the request. That session lets Supabase recognize who is asking. Table grants let the signed-in role try operations such as reading or updating notes. Row policies decide which notes those operations can reach.
Turning off RLS leaves the table grants in force. A secret key or a legacy service-role key can bypass row policies. Keep those keys on the server and use ordinary signed-in sessions for the checks below. See the Supabase RLS reference and guide to choosing the right project key.
Create an explicit owner-only policy
In the disposable project, run this once to create the notes table and its owner rules.
create table public.notes (
id uuid primary key default gen_random_uuid(),
user_id uuid not null references auth.users(id),
title text not null,
content text
);
alter table public.notes enable row level security;
revoke all on public.notes from anon, authenticated;
grant select, insert, update, delete on public.notes to authenticated;
create policy notes_read_own on public.notes
for select to authenticated using ((select auth.uid()) = user_id);
create policy notes_insert_own on public.notes
for insert to authenticated with check ((select auth.uid()) = user_id);
create policy notes_update_own on public.notes
for update to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);
create policy notes_delete_own on public.notes
for delete to authenticated using ((select auth.uid()) = user_id);
USING filters existing rows; WITH CHECK checks new values. This example permits all four operations for the owner. If the application does not need deletion, omit its grant and policy. Do not add capabilities merely to complete a four-policy template.
Test through two normal sessions
Sign in as disposable accounts A and B in separate browser profiles. Save a made-up note for each account, then save a second note as A. Keep A’s first note for the cross-account checks.
Send the checks directly to the disposable project’s Data API, the interface that reads and changes saved notes. Use the project’s publishable key with the ordinary session for A or B as indicated. For the signed-out check, use the publishable key alone. Request the fixture note by its exact ID and let the database policy decide ownership. Check Supabase’s response even if the app hides the note or its controls.
- As A, reopen A’s first note and check the saved title.
- As A, change the title of A’s second note and reload to check the new title was saved. Delete that same note and reload again. It should be gone.
- As B, request A’s first note. The response should reveal none of its contents.
- As B, try to change and delete A’s first note. In A’s session, reload the first note. Its original title and text should still be there.
- As A, try to reassign the first note to B. The change should be refused and A should still own it.
- While signed out, try to read or change a test note. The request should reveal no private data and leave the note unchanged.
A request can return without an error even if it changes zero rows. Have the test request the affected rows. In Supabase’s JavaScript library, add .select() after the update’s filters to see which rows changed. Then reload the note to check what was saved.
Avoid a misleading SQL-editor test
Setting a JWT claim while still executing as a privileged database role does not make a query equivalent to a browser user's request. A table owner or bypass role may ignore RLS.
For a controlled SQL fixture, use a transaction, assume the intended nonprivileged role and set the test identity in that transaction. Use real UUIDs for existing fixture users and roll back afterward. Review role privileges before trusting the result. For an application acceptance test, prefer actual signed-in API clients as described above.
Review shared and indirect access
Owner equality is only one pattern. Team data may require a membership table and explicit roles. Public catalogue reads may intentionally be allowed while writes remain restricted. Review every reachable path, including views, functions, storage objects and privileged server operations.
Policies can combine, so inspect existing policies before adding another one. A permissive policy can widen access beyond the new owner check. Do not disable RLS to fix an empty screen; first inspect the session, grants and matching policy.
Storage has its own access rules. If a bucket is public, a file can still be public even when its path is saved in a private row. Use a separate check for who can open the file itself.
Keep policy changes reviewable
Keep the table definition, grants and policies in migration files so a teammate can review what changes together. Keep the allowed and denied tests alongside them. Record which operations need a privileged role and why. Repeat the two-user checks in the test environment before the app handles customer data.