Fire Storage Exception ([firebase_storage/unauthorized] User is not authorized to perform the desired action.) (my rule is allow read/write)

Viewed 5518

I am trying to get images from firebase firestore, while trying to get image download url there is this exception :

W/StorageUtil(10206): no auth token for request

(similar questions with this error not solve the problem)

Although my security rules allow read and write I getting this error still.

Any ideas what is the problem with this?

Code for getting image url :

  static Future<dynamic> loadImage(BuildContext context, String image) async {
    return await FirebaseStorage.instance.ref().child(image).getDownloadURL();
  }

Calling this loadImage function :

  Future<Widget> getImage(BuildContext context, String imgName) async {
   Image image;
    await FireStorageService.loadImage(context, imgName).then((value) {
    print(value);
    image = Image.network(value.toString(), fit: BoxFit.scaleDown);
    return image;
   });
  }

Calling this getImage function :

child: FutureBuilder(
future: getImage(context, "/images/test1.jpg"),
...
)

My firebase storage rules :

rules_version = '2';
service firebase.storage {
match /images/{imageId} {
  allow read,write;
}
}

Storage Rules ss:

enter image description here

My firebase store currently : My firebase store currently

4 Answers
  • Navigate to Firebase console

  • In Sidebar under Develop open Storage

  • Open Rules tab replace the rule on your console with the rule below:

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

And Publish Done

I fixed it by changing the rules.

Go to Firebase project>Storage>Rules.

By default, you are not allowed to upload on Firebase so you have to change that.

  • Default rules
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if false;
    }
  }
}

Change allow read, write: if false; to allow read, write;

Go to Project Settings -> App Check -> Products Change the Storage from Enforce -> Unenforced 1

This works for me by changing the rules in firebase.

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