Row Level Security (RLS) in Supabase

From the Supabase cheat sheet ยท Authentication ยท verified Jul 2026

Row Level Security (RLS)

Secure database access with policies

sql
-- Enable RLS on table
ALTER TABLE posts ENABLE ROW LEVEL SECURITY;

-- Policy: Users can read all posts
CREATE POLICY "Public posts are readable by everyone"
ON posts FOR SELECT
USING (status = 'published');

-- Policy: Users can only update their own posts
CREATE POLICY "Users can update own posts"
ON posts FOR UPDATE
USING (auth.uid() = author_id);
๐Ÿ”’ Fine-grained access control at database level
๐ŸŽฏ Policies apply automatically to all queries
โšก Better performance than application-level checks
๐Ÿ”‘ Service role key bypasses RLS (use carefully)

More Supabase tasks

Back to the full Supabase cheat sheet