firestore transaction throws error for update rule

2019-07-23 04:24发布

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条回答
▲ chillily
2楼-- · 2019-07-23 04:27

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

查看更多
登录 后发表回答