I am trying to set firestore security so that user can read and write their own document here is code I used to add data to database
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);
}
here is the code to read data
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());
});
});
}
and firestore rule I tried that didn't work
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /orders/{uid} {
allow read, write: if request.resource.data.uid == request.auth.uid;
}
}
}
please how can I achieve this