【发布时间】:2020-07-15 12:31:52
【问题描述】:
我的应用 (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 中)只有在用户登录并且是同一用户时才会创建......关于什么是错了吗?
谢谢。
【问题讨论】:
标签: javascript firebase react-native google-cloud-firestore firebase-security