Created
June 3, 2024 12:46
-
-
Save Jalson1982/6f26460c4f65a67bd212a6afc06fb2e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function addClubsStoragePolicy() { | |
const policyQuery = ` | |
CREATE POLICY "clubs_custom_policy" | |
ON storage.objects | |
FOR SELECT USING ( | |
(bucket_id = 'clubs'::text) AND | |
(EXISTS ( | |
SELECT 1 | |
FROM (permissions | |
JOIN users ON ((users.id = permissions.user_id))) | |
WHERE ( | |
(permissions.club_id = ((storage.foldername(objects.name))[1])::integer) AND | |
(users.uuid = auth.uid()) AND | |
(permissions.module_information_upload_documents = true) | |
) | |
)) AND | |
((storage.foldername(name))[2] = 'documents'::text) | |
) | |
` | |
const { data, error } = await supabase.rpc('pg_exec', { sql: policyQuery }) | |
if (error) { | |
console.error('Error adding/updating clubs policy:', error) | |
} else { | |
console.log('Clubs policy added/updated successfully:', data) | |
} | |
} | |
async function addUsersStoragePolicy() { | |
const policyQuery = ` | |
CREATE POLICY "users_custom_policy" | |
ON storage.objects | |
FOR SELECT USING ( | |
(bucket_id = 'users'::text) AND | |
((SELECT (auth.uid())::text AS uid) = (storage.foldername(name))[1]) | |
) | |
` | |
const { data, error } = await supabase.rpc('pg_exec', { sql: policyQuery }) | |
if (error) { | |
console.error('Error adding/updating users policy:', error) | |
} else { | |
console.log('Users policy added/updated successfully:', data) | |
} | |
} | |
addClubsStoragePolicy() | |
addUsersStoragePolicy() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment