Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upgrade to firebase storage rules v2

Today when I tried to update my firebase storage rules I got a message about upgrading them. How do I do that?

i  deploying storage
i  firebase.storage: checking storage.rules for compilation errors...
⚠  [W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]).
✔  firebase.storage: rules file storage.rules compiled successfully
i  storage: uploading rules storage.rules...
✔  storage: released rules storage.rules to firebase.storage

My rules looks like this:

service firebase.storage {
    match /b/{bucket}/o {
        match /user-files/{uid}/{allPaths=**} {
            allow read: if resource.metadata[request.auth.uid] == "1";  // the uploading user can get a downloadURL
            allow create, update: if request.auth.uid == uid // User can only upload to the users own folder
                && request.auth.token.storageLeft >= request.resource.size
                && request.auth.token.path == request.resource.name
            allow delete: if false; // files are only deleted by cloud functions
        }
    }
}
like image 981
Jørgen Rasmussen Avatar asked Mar 25 '20 10:03

Jørgen Rasmussen


People also ask

How do I change Storage rules in Firebase?

Once you know who they are, you need a way to control their access to files in Cloud Storage. You can edit these rules by selecting a Firebase app in the Firebase console and viewing the Rules tab of the Storage section.

How do I enable Storage permissions in Firebase?

go to "Storage" Select "Rules" tab and edit rules as per below: service firebase. storage { match /b/{bucket}/o { match /{allPaths=**} { // Allow access by all users allow read, write: if request. auth !=

How do I get Firebase Storage access token?

You can do this with the Cloud Storage SDK, which is bundled with the Firebase Admin SDK and accessible by calling admin. storage() . Now, calling the client-side method getDownloadUrl() on the file reference will give you a download URL that contains your newly created token.


1 Answers

To switch your rules to version 2, add this line at the top:

rules_version = "2";

To learn more about the new version of the rules language, see the documentation on getting started.

like image 155
Frank van Puffelen Avatar answered Oct 23 '22 16:10

Frank van Puffelen