2
votes

by execution of firestore runTransaction function on the web, it occurs error below.

firestore.googleapis.com/v1beta1/projects/myproject/databases/(default)/documents:commit:1 POST https://firestore.googleapis.com/v1beta1/projects/myproject/databases/(default)/documents:commit 403

i want to allow only update one field for everyone and others are for login user.

so update rule uses next.

allow update: if request.resource.data.keys().hasOnly(["numPlayed"]) 
|| request.auth.uid != null;

and transaction codes like

this.db.runTransaction(function(t) {
    return t.get(pubRef)
    .then(function(pub) {
        var numPlayed = pub.data().numPlayed + 1;
        t.update(pubRef, { numPlayed: numPlayed });
        return numPlayed;
    });
})

why it occurs error?

1

1 Answers

0
votes

I finally got the reason. 'runTransaction' requires write authority not a divided like update.