What is the purpose of update and delete policies in Supabase?
They control who can change or remove data in your database, ensuring only authorized users can perform these actions.
Click to reveal answer
beginner
How do you write a simple update policy in Supabase?
You write a policy using SQL-like expressions that check conditions, for example: auth.uid() = user_id to allow users to update only their own data.
Click to reveal answer
beginner
Why is it important to have delete policies in your database?
Delete policies prevent accidental or malicious removal of data by restricting who can delete records, protecting data integrity.
Click to reveal answer
beginner
What happens if you do not set update or delete policies in Supabase?
By default, no one can update or delete data unless policies explicitly allow it, so your data remains safe from unauthorized changes.
Click to reveal answer
intermediate
Can update and delete policies use multiple conditions in Supabase?
Yes, you can combine conditions using AND/OR to create precise rules, like allowing updates only if the user owns the record and the record is active.
Click to reveal answer
What does an update policy in Supabase control?
AWho can create new data
BWho can read data
CWho can change existing data
DWho can backup data
✗ Incorrect
Update policies define who is allowed to modify existing records in the database.
If no delete policy is set, who can delete data in Supabase?
ANo one
BOnly admins
COnly the data owner
DAnyone
✗ Incorrect
By default, no delete operations are allowed unless a policy explicitly permits it.
Which function is commonly used in Supabase policies to check the current user ID?
Aauth.uid()
Bcurrent_user()
Cuser_id()
Dsession.user()
✗ Incorrect
The function auth.uid() returns the ID of the authenticated user for policy checks.
Can you combine multiple conditions in a Supabase update policy?
ANo, only one condition is allowed
BYes, using AND/OR operators
COnly OR is allowed
DOnly AND is allowed
✗ Incorrect
Supabase policies support combining multiple conditions with AND and OR for precise control.
What is a best practice when creating delete policies?
AAllow delete only during business hours
BAllow everyone to delete
CDisable delete policies
DRestrict delete to authorized users only
✗ Incorrect
Restricting delete operations to authorized users protects data from accidental or malicious loss.
Explain how update policies work in Supabase and why they are important.
Think about who should be allowed to change data and how Supabase checks user identity.
You got /3 concepts.
Describe the default behavior of Supabase when no delete policies are set and how to properly secure delete operations.
Consider what happens if you forget to set delete rules and how to prevent unwanted data loss.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of an UPDATE policy in Supabase?
easy
A. To control who can add new data to a table
B. To control who can read data from a table
C. To control who can change existing data in a table
D. To control who can create new tables
Solution
Step 1: Understand the role of update policies
Update policies define who is allowed to modify existing rows in a table.
Step 2: Differentiate from other policies
Read policies control reading, insert policies control adding data, and table creation is unrelated.
Final Answer:
To control who can change existing data in a table -> Option C
Quick Check:
Update policy = control data changes [OK]
Hint: Update policies control data changes, not reads or inserts [OK]
Common Mistakes:
Confusing update with read or insert policies
Thinking update policies control table creation
Assuming update policies allow adding new rows
2. Which keyword is used in Supabase policies to add extra conditions that must be true for an update to succeed?
easy
A. WITH CHECK
B. USING
C. ALLOW
D. WHERE
Solution
Step 1: Identify keywords for policy conditions
Supabase uses USING to specify who can perform an action and WITH CHECK to add extra conditions on updates.
Step 2: Match keyword to extra conditions on update
WITH CHECK ensures the new data meets certain rules before update is allowed.
Final Answer:
WITH CHECK -> Option A
Quick Check:
Extra update conditions = WITH CHECK [OK]
Hint: Use WITH CHECK for extra update conditions, USING for who can act [OK]
Common Mistakes:
Confusing USING and WITH CHECK keywords
Thinking WHERE is used in policies
Assuming ALLOW is a valid keyword
3. Given this update policy snippet:
CREATE POLICY "Update own profile" ON profiles
FOR UPDATE
USING (auth.uid() = profiles.user_id)
WITH CHECK (auth.uid() = profiles.user_id);
What happens if a user tries to update another user's profile?
medium
A. The update is allowed because USING only controls delete actions
B. The update is denied because WITH CHECK condition fails
C. The update is allowed because WITH CHECK is ignored
D. The update is denied because USING condition fails
Solution
Step 1: Understand USING condition role
The USING clause controls who can perform the update. It checks if the user's ID matches the profile's user_id.
Step 2: Check condition for updating another user's profile
If a user tries to update a different profile, auth.uid() = profiles.user_id is false, so update is denied.
Final Answer:
The update is denied because USING condition fails -> Option D
Quick Check:
USING controls update permission = denied if false [OK]
Hint: USING controls who can update; false means deny [OK]
Common Mistakes:
Thinking WITH CHECK controls permission to update
Assuming USING applies only to deletes
Ignoring that both USING and WITH CHECK must pass
4. You wrote this delete policy:
CREATE POLICY "Delete own posts" ON posts
FOR DELETE
USING (user_id = auth.uid());
But users report they cannot delete their posts. What is the likely problem?
medium
A. The policy should use WITH CHECK instead of USING
B. The policy might be missing enabling RLS on the table
C. The policy is correct; problem is elsewhere
D. The policy is missing FOR UPDATE clause
Solution
Step 1: Check policy syntax
The policy syntax is correct for delete with USING condition matching user_id.
Step 2: Consider RLS status
If Row Level Security (RLS) is not enabled on the table, policies have no effect and all actions are denied by default.
Final Answer:
The policy might be missing enabling RLS on the table -> Option B
Quick Check:
RLS must be enabled for policies to work [OK]
Hint: Enable RLS on table to activate policies [OK]
Common Mistakes:
Confusing USING and WITH CHECK for delete policies
Forgetting to enable RLS on the table
Thinking FOR UPDATE is needed for delete policies
5. You want to allow users to update their own orders only if the order status is not 'shipped'. Which policy correctly enforces this?
hard
A. FOR UPDATE USING (auth.uid() = orders.user_id) WITH CHECK (new.status != 'shipped')
B. FOR UPDATE USING (auth.uid() = orders.user_id) WITH CHECK (orders.status != 'shipped')
C. FOR UPDATE USING (auth.uid() = orders.user_id AND orders.status != 'shipped')
D. FOR UPDATE USING (auth.uid() = orders.user_id AND new.status != 'shipped')
Solution
Step 1: Understand USING vs WITH CHECK
USING controls who can perform the update; WITH CHECK ensures the new data meets conditions.
Step 2: Apply condition on new data
The status check must apply to the new value after update, so use new.status != 'shipped' in WITH CHECK.
Step 3: Verify options
FOR UPDATE USING (auth.uid() = orders.user_id) WITH CHECK (new.status != 'shipped') correctly uses USING (auth.uid() = orders.user_id) and WITH CHECK (new.status != 'shipped').
Final Answer:
FOR UPDATE USING (auth.uid() = orders.user_id) WITH CHECK (new.status != 'shipped') -> Option A
Quick Check:
Use WITH CHECK with new. for update conditions [OK]
Hint: Use WITH CHECK with new. to check updated values [OK]
Common Mistakes:
Checking old data instead of new data in WITH CHECK
Putting status condition in USING instead of WITH CHECK
Forgetting to use new. prefix for updated row
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.