mercredi 9 novembre 2016

Firebase throws/catch no error on upload with permission denied

            // Create storage ref.
            var storageCategory = storageCategories.child(name + "." + extension);
            // Upload file.
            var upload = storageCategory.put(file);
            upload.on("state_changed",
                function (snapshot) {

                },
                function (error) {
                    // TODO Why is this never called?
                    console.log("Some error.");
                },
                function () {
                    console.log("Everything ok.");
                }
            );

So, I have this simple (by-the-book) JavaScript upload task. Everything works ok when I'm logged in with user that have permission (toza@vanligvis.com). File uploads, file is in Firebase storage. BUT, when I log in with another user that does NOT have write permission (checked by the rules), all I got (in browser console) are these "POST - 403 forbidden" messages. That is expected, but why Firebase doesn't call function (error) {}?

Screenshot

My Firebase storage rules are:

service firebase.storage {
  match /b/ecommerce-68bae.appspot.com/o {
    match /{allPaths=**} {
    allow write: if request.auth != null && isAdmin();
    allow read;
    }
  }
}

function isAdmin() {
    return request.auth.uid in {
        "S0Zmjh6K3tdNydQFarDKzytvcUt2":"toza@vanligvis.com"
    };
}

What am I missing? How to detect upload forbidden error? Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire