【发布时间】:2020-04-21 08:13:44
【问题描述】:
我的代码
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:缺失或不足 权限。
帮助解决问题
【问题讨论】:
-
您是否已登录或已通过身份验证?由于您的规则
allow read, update, delete: if request.auth.uid == resource.data.uid会阻止您的请求,因此会发生此错误。 -
我试过这个,同样的问题:service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read: if true;允许写入:如果为假; } } }
-
提升它的实际效果
-
你确定
this.messages代表messages集合吗?
标签: javascript firebase vue.js google-cloud-firestore firebase-security