firestore transaction throws error for update rule which allows only has one specific field

ぃ、小莉子 提交于 2019-12-23 22:08:04

问题


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:


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



来源:https://stackoverflow.com/questions/52523941/firestore-transaction-throws-error-for-update-rule-which-allows-only-has-one-spe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!