-- Users can upload to moodboards/<their uid>/...
CREATE POLICY "Users upload to own moodboard folder"
  ON storage.objects FOR INSERT TO authenticated
  WITH CHECK (
    bucket_id = 'moodboards'
    AND (storage.foldername(name))[1] = auth.uid()::text
  );

CREATE POLICY "Users read own moodboard files"
  ON storage.objects FOR SELECT TO authenticated
  USING (
    bucket_id = 'moodboards'
    AND (storage.foldername(name))[1] = auth.uid()::text
  );

CREATE POLICY "Users delete own moodboard files"
  ON storage.objects FOR DELETE TO authenticated
  USING (
    bucket_id = 'moodboards'
    AND (storage.foldername(name))[1] = auth.uid()::text
  );