【发布时间】:2018-09-11 05:21:23
【问题描述】:
我想保证用户只能添加与其 auth.uid 具有相同 id 的文档。
例如,id 为 1X0T6xC6hhRN5H02zLCN6SQtwby2 的用户只能创建/更新文档 /salesmen/1X0T6xC6hhRN5H02zLCN6SQtwby2 。
在应用级别,通过以下命令完成(创建和更新)。
this.db
.collection("salesmen")
.doc(user.uid)
.set(data)
.then(function() { //...
在 Firestore 级别,我正在尝试以下规则,但它不起作用(导致 写入文档时出错:错误:权限缺失或不足。)。
match /salesmen/{salesman} {
allow read: if true;
allow write: if request.auth != null && resource.id == request.auth.uid;
}
如何执行这条规则?
【问题讨论】:
标签: firebase firebase-realtime-database firebase-authentication google-cloud-firestore