Preparing your workspace
Supabase Storage access can be controlled through policies so file operations follow the same authorization rules as application data.
Secure file storage requires more than choosing a private bucket. Storage operations should be restricted using appropriate policies and user identity checks. A common pattern is to store files under paths containing a user or organization identifier and then enforce policies that only allow authorized users to access matching paths. Signed URLs can provide temporary access to private files. File type, size, and ownership checks should also happen at application and policy levels where appropriate.
Students may upload assignments into their own organization or user folders, while mentors can access only the students assigned to them.
create policy "Users can upload their own files" on storage.objects for insert to authenticated with check ( bucket_id = 'documents' and (storage.foldername(name))[1] = (select auth.uid()::text) );
The policy allows authenticated users to upload files only into paths whose first folder matches their own user ID.