Reputation: 35203
Using the Supabase Storage API, I am calling:
const createBucketRes = await supabase.storage.createBucket('avatars')
But I am getting the error
StorageApiError: new row violates row-level security policy
I am able to use the dashboard to create a bucket and set policies there, but then what is the purpose of having the API?
Reference: https://supabase.com/docs/guides/storage/quickstart?queryGroups=language&language=javascript
Upvotes: 1
Views: 47
Reputation: 2725
You would have to define RLS policies to allow all users to create buckets.
Something like:
create policy "allow all users to create buckets"
ON storage.buckets
for insert with check (
true
);
Or alternatively use the service role key as auth for the supabase client.
export default async function getSupabaseServerAdminClient() {
const supabase = createClient<Database>(
process.env.SUPABASE_URL!,
process.env.SUPABASE_SERVICE_ROLE_KEY!,
{
auth: {
persistSession: false,
autoRefreshToken: false,
detectSessionInUrl: false,
},
},
);
return supabase;
}
Upvotes: 1