What is the purpose of storage policies in Supabase?
Storage policies control who can access or modify files in Supabase storage buckets. They help keep data safe by setting rules for reading and writing files.
Click to reveal answer
beginner
How do you define a storage policy in Supabase?
You write a policy using SQL-like syntax that specifies conditions under which users can perform actions like SELECT (read) or INSERT (upload) on storage objects.
Click to reveal answer
intermediate
What does the 'auth.uid()' function do in Supabase storage policies?
It returns the unique ID of the currently logged-in user, allowing policies to check if the user owns the file or has permission to access it.
Click to reveal answer
beginner
Why is it important to restrict public access in storage policies?
Restricting public access prevents unauthorized users from reading or modifying files, protecting sensitive data and user privacy.
Click to reveal answer
intermediate
Give an example condition to allow users to read only their own files in Supabase storage.
A condition like: "bucket_id = 'user-files' AND auth.uid() = metadata->>'user_id'" ensures users can only access files tagged with their own user ID.
Click to reveal answer
What does a storage policy in Supabase control?
AThe color of the storage interface
BHow fast files upload
CThe size limit of the database
DWho can read or write files in storage buckets
✗ Incorrect
Storage policies define access rules for reading and writing files in Supabase storage.
Which function helps identify the current user in a Supabase storage policy?
Aauth.uid()
Bcurrent_user()
Cuser_id()
Dget_user()
✗ Incorrect
auth.uid() returns the unique ID of the logged-in user for access checks.
Why should you avoid making storage buckets publicly readable?
ATo reduce storage costs
BTo speed up file downloads
CTo protect sensitive files from unauthorized access
DTo allow anyone to upload files
✗ Incorrect
Public read access can expose private data, so restricting it improves security.
In a storage policy, what does the condition "auth.uid() = metadata->>'user_id'" mean?
AUser can access files they own
BUser can access all files
CUser cannot access any files
DUser can only upload files
✗ Incorrect
This condition allows users to access only files tagged with their own user ID.
Which action does the 'SELECT' keyword control in Supabase storage policies?
AUploading files
BReading files
CDeleting files
DRenaming files
✗ Incorrect
'SELECT' controls permission to read or download files from storage.
Explain how storage policies help secure files in Supabase storage.
Think about who can see or change files and how policies set rules for that.
You got /4 concepts.
Describe a simple policy condition that allows users to only read their own files.
Focus on matching user identity with file ownership.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of storage policies in Supabase?
easy
A. To increase storage space automatically
B. To speed up file uploads
C. To control who can read, upload, or delete files
D. To backup files to another server
Solution
Step 1: Understand storage policies
Storage policies define rules about who can access or change files.
Step 2: Identify the main goal
The main goal is to control access like reading, uploading, or deleting files to keep data safe.
Final Answer:
To control who can read, upload, or delete files -> Option C
Quick Check:
Storage policies = Access control [OK]
Hint: Storage policies = who can do what with files [OK]
Common Mistakes:
Thinking policies increase storage size
Confusing policies with backup features
Believing policies speed up uploads
2. Which of the following is the correct syntax to allow only authenticated users to read files in Supabase storage policy?
easy
A. allow read if user.is_authenticated
B. using (auth.uid() != null)
C. check auth.user == true
D. permit read where auth.id exists
Solution
Step 1: Recall Supabase policy syntax
Supabase uses SQL-like expressions with functions like auth.uid() to check user identity.
Step 2: Identify correct condition for authenticated users
auth.uid() returns user ID if logged in, so checking auth.uid() != null allows only authenticated users.
Final Answer:
using (auth.uid() != null) -> Option B
Quick Check:
auth.uid() != null = authenticated user check [OK]
Hint: Use auth.uid() to check if user is logged in [OK]
Common Mistakes:
Using incorrect property names like user.is_authenticated
Writing non-SQL syntax like permit or allow keywords
Checking auth.id instead of auth.uid()
3. Given this storage policy snippet:
using (bucket_id = 'public' OR auth.uid() = owner_id)
What does this policy allow?
medium
A. Anyone can access files in the 'public' bucket or owners can access their files
B. Only owners can access files in any bucket
C. Only users with bucket_id 'public' can access files
D. No one can access files unless they are owners
Solution
Step 1: Analyze the condition
The condition allows access if bucket_id equals 'public' OR if the user's ID matches owner_id.
Step 2: Interpret the meaning
This means anyone can access files in the 'public' bucket, and owners can access their own files in any bucket.
Final Answer:
Anyone can access files in the 'public' bucket or owners can access their files -> Option A
Quick Check:
bucket_id='public' OR auth.uid()=owner_id = public or owner access [OK]
Hint: OR means either public bucket or owner access allowed [OK]
Common Mistakes:
Thinking only owners have access
Assuming bucket_id restricts all access
Ignoring the OR condition
4. You wrote this policy:
using (auth.uid() = owner_id AND bucket_id = 'private')
But users report they cannot read their private files. What is the likely problem?
medium
A. The policy blocks access because AND requires both conditions, but bucket_id might differ
B. auth.uid() is not a valid function
C. owner_id should be replaced with user_id
D. Policies cannot use AND conditions
Solution
Step 1: Understand the AND condition
AND means both auth.uid() = owner_id and bucket_id = 'private' must be true for access.
Step 2: Identify why access fails
If bucket_id is not exactly 'private' for some files, even owners cannot access them, causing the problem.
Final Answer:
The policy blocks access because AND requires both conditions, but bucket_id might differ -> Option A
Quick Check:
AND requires both true, bucket_id mismatch blocks access [OK]
Hint: AND means all conditions must match exactly [OK]
Common Mistakes:
Thinking auth.uid() is invalid
Assuming owner_id is wrong field
Believing AND is not allowed in policies
5. You want to create a policy that allows users to delete only files they own in any bucket except the 'public' bucket. Which policy condition is correct?
hard
A. using (auth.uid() != owner_id AND bucket_id = 'public')
B. using (auth.uid() = owner_id OR bucket_id != 'public')
C. using (auth.uid() = owner_id AND bucket_id = 'public')
D. using (auth.uid() = owner_id AND bucket_id != 'public')
Solution
Step 1: Define the requirements
Users can delete files only if they own them and the file is not in the 'public' bucket.
Step 2: Match the condition
auth.uid() = owner_id ensures ownership; bucket_id != 'public' excludes the public bucket.
Final Answer:
using (auth.uid() = owner_id AND bucket_id != 'public') -> Option D
Quick Check:
Owner AND not public bucket = correct delete policy [OK]
Hint: Use AND to combine ownership and bucket exclusion [OK]
Common Mistakes:
Using OR instead of AND allowing wrong deletes
Checking for equality with 'public' instead of exclusion
Mixing up != and = operators
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.