You have a table orders with a Row Level Security (RLS) policy that allows users to see only their own orders based on user_id. What will be the result of the following query when run by user with user_id = 5?
SELECT * FROM orders;
CREATE POLICY user_orders ON orders FOR SELECT USING (user_id = auth.uid());
Think about how RLS filters rows based on the policy condition.
The RLS policy restricts SELECT queries to rows where user_id matches the current user's ID (5). So only those rows are returned.
Consider a table profiles with RLS enabled but no UPDATE policy defined. What happens when a user tries to update their own profile?
ALTER TABLE profiles ENABLE ROW LEVEL SECURITY;
Remember what happens when no policy exists for a command with RLS enabled.
When RLS is enabled and no policy exists for UPDATE, all UPDATE commands are denied by default, causing a permission error.
You want to test if your RLS policy correctly restricts DELETE operations to the owner of the row. Which SQL command will simulate a DELETE as a user with auth.uid() = 'abc123'?
Supabase uses JWT claims to identify users in RLS policies.
Setting jwt.claims.sub simulates the authenticated user's ID for RLS evaluation in Supabase.
You are designing a multi-tenant app where each tenant's data is stored in the same table with a tenant_id column. Which RLS policy best ensures users see only their tenant's data?
Consider how tenant context is passed securely to the database.
Using a session variable like app.current_tenant allows the app to set tenant context securely for RLS filtering.
You have enabled RLS on a table documents. You want to ensure users can only SELECT, INSERT, UPDATE, and DELETE their own documents. Which set of policies covers all these commands correctly?
Remember that INSERT policies require WITH CHECK clauses and UPDATE policies need both USING and WITH CHECK.
Option A correctly defines separate policies for each command with proper USING and WITH CHECK clauses to restrict access to the owner's documents.
