CREATE POLICY "Users can view their tasks" ON tasks FOR SELECT USING (user_id = auth.uid());
What will happen if user with ID '123' queries SELECT * FROM tasks;?
medium
A. They will see all tasks regardless of user_id.
B. They will see only tasks where user_id is '123'.
C. They will get an error about missing permissions.
D. They will see no tasks at all.
Solution
Step 1: Understand the policy condition
The policy allows SELECT only if user_id = auth.uid(), meaning user sees rows matching their own ID.
Step 2: Apply to user ID '123'
User '123' will see only rows where user_id equals '123'.
Final Answer:
They will see only tasks where user_id is '123'. -> Option B
Quick Check:
RLS filters rows by user_id = auth.uid() [OK]
Hint: RLS filters rows by matching user ID [OK]
Common Mistakes:
Assuming all rows are visible
Expecting permission error without policy
Thinking no rows will show
4. You created this RLS policy:
CREATE POLICY "Allow users to update their profiles" ON profiles FOR UPDATE USING (user_id = auth.uid());
But users report they cannot update their profiles. What is the most likely cause?
medium
A. The auth.uid() function is misspelled.
B. The policy uses FOR UPDATE instead of FOR SELECT.
C. The user_id column does not exist in profiles.
D. RLS is not enabled on the profiles table.
Solution
Step 1: Check RLS enablement
Even with a policy, RLS must be enabled on the table to enforce it.
Step 2: Identify cause of update failure
If RLS is disabled, policies don't apply, so updates may be blocked or unrestricted incorrectly.
Final Answer:
RLS is not enabled on the profiles table. -> Option D
Quick Check:
Enable RLS before policies work [OK]
Hint: Enable RLS before creating policies [OK]
Common Mistakes:
Confusing policy action with table RLS status
Assuming policy syntax error causes issue
Ignoring RLS enablement step
5. You want to allow users to see their own orders and also let admins see all orders. Which RLS policy setup achieves this safely?
hard
A. CREATE POLICY "Admins only" ON orders FOR SELECT USING (auth.role() = 'admin');
B. CREATE POLICY "Users only" ON orders FOR SELECT USING (user_id = auth.uid());
C. CREATE POLICY "Users and admins" ON orders FOR SELECT USING (user_id = auth.uid() OR auth.role() = 'admin');
D. No RLS needed if admins have full access.
Solution
Step 1: Identify user and admin access needs
Users see their own orders; admins see all orders.
Step 2: Write policy condition combining both
Use user_id = auth.uid() OR auth.role() = 'admin' to allow both cases.
Step 3: Verify policy covers both roles safely
CREATE POLICY "Users and admins" ON orders FOR SELECT USING (user_id = auth.uid() OR auth.role() = 'admin'); correctly implements this combined condition.
Final Answer:
CREATE POLICY "Users and admins" ON orders FOR SELECT USING (user_id = auth.uid() OR auth.role() = 'admin'); -> Option C
Quick Check:
Combine user and admin checks in policy [OK]
Hint: Use OR to combine user and admin access in RLS [OK]
Common Mistakes:
Creating separate policies without OR condition
Assuming admins need no RLS
Allowing all users to see all data
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.