In Supabase, you want to allow users to read only their own data from a table with Row Level Security enabled. Which policy condition correctly restricts read access to the current user's rows?
Think about how to match the current user's ID with the row's user ID.
The condition auth.uid() = user_id ensures that users can only read rows where the user_id column matches their own user ID. Other options either allow too broad access or do not restrict to the current user.
You want to allow anyone (even unauthenticated users) to read all rows from a public table in Supabase. Which policy condition should you use?
Think about allowing access without checking user identity.
Using TRUE as the condition allows all users, including unauthenticated ones, to read all rows. Other conditions restrict access to authenticated users or specific user IDs.
You have a table where admins can read all rows, but regular users can only read their own rows. Which combination of policy conditions correctly implements this?
Admins should have full read access, users only their own rows.
Policy 1 allows admins to read all rows. Policy 2 restricts regular users to their own rows by matching auth.uid() with user_id. Other options either allow too broad access or do not restrict properly.
If Row Level Security is enabled on a table but no SELECT policy exists, what happens when a user tries to read data from that table?
Think about default behavior of RLS when no policies exist.
When RLS is enabled, access is denied by default unless a policy explicitly allows it. Without a SELECT policy, no reads are permitted.
In a multi-tenant Supabase app, each row has a tenant_id column. What is the best policy condition to ensure users only read data belonging to their tenant?
Consider how tenant information is passed securely in JWT claims.
The best practice is to use the tenant ID from the user's JWT token to match the tenant_id column, ensuring users only access their tenant's data. Using auth.uid() matches user ID, not tenant. TRUE allows all access, and auth.role() does not restrict by tenant.
