【发布时间】:2020-06-24 17:55:30
【问题描述】:
我要疯了……
Firestore 规则:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{documents=**} {
allow read, write;
}
}
}
颤动代码(cloud_firestore:^0.13.4+1):
FirebaseAuth.instance.signInAnonymously()
.then((AuthResult result) async {
DocumentSnapshot snapshot = await Firestore.instance.collection("users").document("FzI6D1BIvdTU4htj5qeISev8pIo1").get();
print(snapshot.data.toString());
})
.catchError((error) => print("Firestore error: " + error.toString()));
调试结果:
W/Firestore(18991): (21.3.0) [Firestore]: Listen for Query(users/FzI6D1BIvdTU4htj5qeISev8pIo1) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
I/flutter (18991): Firestore error: PlatformException(Error performing get, PERMISSION_DENIED: Missing or insufficient permissions., null)
- 我尝试使用有效的电子邮件+密码成功登录;同样的错误。
- 在 Firestore 的“规则游乐场”中,一切正常,无需任何 PERMISSION_DENIED。
- 文档“/users/FzI6D1BIvdTU4htj5qeISev8pIo1”存在,但即使不存在,也不应该失败。
【问题讨论】:
-
尝试将
allow read, write;更改为allow read, write: if true;
标签: firebase flutter google-cloud-firestore firebase-security permission-denied