我正在尝试设置 firestore 安全性,以便用户可以读取和写入自己的文档,这是我用来将数据添加到数据库的代码
data() {
return {
order: {
price: null,
amount: null,
comment: null,
createdAt: new Date().toString().slice(0, 25),
uid: fb.auth().currentUser.uid
}
}
}
sendBuy() {
db.collection("orders").add(this.order);
}
Run Code Online (Sandbox Code Playgroud)
这是读取数据的代码
readData() {
let uid = fb.auth().currentUser.uid;
db.collection("orders")
.where("uid", "==", uid)
.get()
.then(querySnapShot => {
querySnapShot.forEach(doc => {
console.log(doc.id, "=>", doc.data());
});
});
}
Run Code Online (Sandbox Code Playgroud)
我尝试过的 firestore 规则不起作用
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /orders/{uid} {
allow read, write: if request.resource.data.uid == request.auth.uid;
}
}
}
Run Code Online (Sandbox Code Playgroud)
请问我怎样才能实现这个目标