Share

RLS policy template for owner-only tables

Open · 8 views · asked by mira_dev · edited

Nine out of ten "RLS blocks my insert" questions here end with this snippet. Replace user_id with your column.

Snippet
Copied 19 times
alter table your_table enable row level security;

create policy "owner reads" on your_table for select using (auth.uid() = user_id);
create policy "owner writes" on your_table for insert with check (auth.uid() = user_id);
create policy "owner updates" on your_table for update using (auth.uid() = user_id) with check (auth.uid() = user_id);
create policy "owner deletes" on your_table for delete using (auth.uid() = user_id);

-- So the client can never forget it:
alter table your_table alter column user_id set default auth.uid();
Comment

Activity