Firebase Storage "Permission denied" error

Viewed 2352

When I try to read my Firebase Storage data I'm getting the following error:

Uncaught (in promise) FirebaseError: Firebase Storage: An unknown error occurred, please check the error payload for server response. (storage/unknown)
{
  "error": {
    "code": 400,
    "message": "Permission denied. Please enable Firebase Storage for your bucket by visiting the Storage tab in the Firebase Console and ensure that you have sufficient permission to properly provision resources."
  }
} 

But my rules are set to public:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

What am I missing? Here's my code:

export const getAll = async () => {
    let list: Photo[] = [];

    const imagesFolder = ref(storage, "images");
    const photoList = await listAll(imagesFolder);

    for(let i in photoList.items) {
        let photoUrl = await getDownloadURL(photoList.items[i]);

        list.push({
            name: photoList.items[i].name,
            url: photoUrl
        });
    }

    return list;
}
1 Answers

Following the steps in this post fixed my issue:

This is due to a missing permission:

firebase-storage@system.gserviceaccount.com
  1. Go to https://console.cloud.google.com
  2. Select your project in the top blue bar
  3. Scroll down the left menu and select "Cloud Storage"
  4. Select all your buckets then click "ADD PRINCIPAL" on the right
  5. Add "firebase-storage@system.gserviceaccount.com" and "Storage Admin" as a role
  6. Save it

https://newbedev.com/firebase-storage-security-rules-400-error-issue-permission-denied-could-not-access-bucket-xxxxx-appspot-com

Related