Javascript 为什么我对firestore don';不行?
我的代码Javascript 为什么我对firestore don';不行?,javascript,firebase,vue.js,google-cloud-firestore,firebase-security,Javascript,Firebase,Vue.js,Google Cloud Firestore,Firebase Security,我的代码 created(){ let ref = db.collection('messages').orderBy('timestamp') // subscribe to changes to the 'messages' collection ref.onSnapshot(snapshot => { snapshot.docChanges().forEach(change => { if(change.type == 'added'){ let d
created(){
let ref = db.collection('messages').orderBy('timestamp')
// subscribe to changes to the 'messages' collection
ref.onSnapshot(snapshot => {
snapshot.docChanges().forEach(change => {
if(change.type == 'added'){
let doc = change.doc
this.messages.push({
id: doc.id,
name: doc.data().name,
content: doc.data().content,
timestamp: moment(doc.data().timestamp).format('lll')
})
}
})
})
我的firebase规则:
service cloud.firestore { match /databases/{database}/documents {
match /messages/{document=**} {
allow read, update, delete: if request.auth.uid == resource.data.uid;
allow create: if request.auth.uid != null;
}
}}
我的错误
onSnapshot中的未捕获错误:FirebaseError:丢失或不足
权限
帮助解决问题查看文档
您只允许满足request.auth.uid==resource.data.uid
的读取操作,但您正在尝试读取整个db.collection('messages')
集合
尝试读取db.collection('messages')。其中('uid','==',currentUserUid)
(不要忘记在消息中实际放置uid
属性。)
附言:你的规则看起来像是个人笔记,而不是用户之间的信息。如果希望收件人与作者不同,则必须更改数据结构和规则。可能有
authorUid
和recipientUid
字段,我不知道,我还没有在Firestore中做过类似的事情。您是否登录或验证过?发生此错误的原因是您的规则允许读取、更新、删除:if request.auth.uid==resource.data.uid
,它阻止了您的请求。我尝试了此规则,同样的问题:service cloud.firestore{match/databases/{database}/documents{match/{document=**}{allow read if true;allow write:if false;}ups it实际工作您确定this.messages
表示messages
集合吗?