![](/img/trans.png)
[英]Uncaught (in promise) FirebaseError: Missing or insufficient permissions. at new Rr
[英]Firebase Uncaught Error in onSnapshot: [FirebaseError: Missing or insufficient permissions.]
我的应用程序(onSnapshot)上有一个firestore监听器,当我创建它时出现错误
onSnapshot 中未捕获的错误:[FirebaseError:缺少权限或权限不足。]
useEffect(() => {
const { firebase } = props;
// Realtime database listene
const unsuscribe = firebase
.getDatabase()
.collection("posts")
.doc(firebase.getCurrentUser().uid)
.collection("userPosts")
.onSnapshot((snapshot) => {
let changes = snapshot.docChanges();
changes.forEach((change) => {
if (change.type === "added") {
console.log(change.doc.data());
// TODO - Add the new post to the posts list
}
});
});
return () => {
// Detach the listening agent
unsuscribe();
};
}, []);
我一直在检查我的权限,但似乎很好:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth.uid != null;
}
function isSameUser(userId) {
return request.auth.uid == userId;
}
match /posts/{userId}/userPosts {
allow read: if true;
allow write, update, delete: if isSignedIn() && isSameUser(userId);
}
}
}
如您所见,表示用户帖子的文档(在 /posts/{userId}/userPosts 中)只有在用户登录并且是否是同一用户时才会创建......关于这里有什么问题的任何想法?
谢谢你。
好的,我有解决方案。 我在这里写它是因为它可能对将来的某人有用。
做就是了:
match /posts/{userId}/userPosts/{document=**} {
allow read: if true;
allow write, update, delete: if isSignedIn() && isSameUser(userId);
}
并且会正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.