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)