Bucket Storage

Automatic bucket creation

The respective file is in charge of verifying if the database connection exists, if it is set to true it verifies if the bucket is created, if it is not, it will create it automatically but first it must create a policy for this.

const createPolicyQuery = `create policy "Allow bucket creation" on storage.buckets for insert with check ( true ); create policy "Allow object creation" on storage.objects for insert with check (true);`;
const queryResponse = await databaseManager.query(createPolicyQuery);

If you want to add a new policy to the bucket you can do it there.

This way you will be able to create the bucket after having created the corresponding policies:

const supabaseUrl = process.env.SUPABASE_URL+'/storage/v1';
const supabaseKey = process.env.SUPABASE_ANON_KEY;

const responseBucket = await fetch(`${supabaseUrl}/bucket`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${supabaseKey}`
    },
    body: JSON.stringify({
        "name": bucketName,
        "public": true
    })
})
const data = await responseBucket.json();

In the case that one of the 2 is not created, it will automatically take care of creating them for you, but if you want to modify, touch or improve the creation of the automatic buckets, this is the file!

Última actualización