-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_storage_policies.sql
More file actions
41 lines (34 loc) · 1.47 KB
/
Copy pathfix_storage_policies.sql
File metadata and controls
41 lines (34 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- =====================================================
-- FIX STORAGE POLICIES
-- Run this in Supabase SQL Editor to fix 403 Errors
-- =====================================================
-- 1. Create the 'documents' bucket if it doesn't exist
INSERT INTO storage.buckets (id, name, public)
VALUES ('documents', 'documents', true)
ON CONFLICT (id) DO UPDATE
SET public = true; -- FORCE PUBLIC for guest uploads
-- 2. Drop existing policies to avoid conflicts
DROP POLICY IF EXISTS "Public Access" ON storage.objects;
DROP POLICY IF EXISTS "Allow Uploads" ON storage.objects;
DROP POLICY IF EXISTS "Allow Deletes" ON storage.objects;
DROP POLICY IF EXISTS "Allow Document Uploads" ON storage.objects;
DROP POLICY IF EXISTS "Allow Authenticated Downloads" ON storage.objects;
-- 3. Create Permissive Policies (Guest Mode)
-- Allow ANYONE to upload files to 'documents' bucket
CREATE POLICY "Allow Public Uploads"
ON storage.objects FOR INSERT
WITH CHECK ( bucket_id = 'documents' );
-- Allow ANYONE to view/download files (since bucket is public)
CREATE POLICY "Allow Public Downloads"
ON storage.objects FOR SELECT
USING ( bucket_id = 'documents' );
-- Allow ANYONE to delete (Optional - maybe restrict this in production)
-- Useful for development so you can clear bad uploads
CREATE POLICY "Allow Public Deletes"
ON storage.objects FOR DELETE
USING ( bucket_id = 'documents' );
-- 4. Verify Setup
DO $$
BEGIN
RAISE NOTICE 'Storage policies fixed! Bucket "documents" is now PUBLIC.';
END $$;