【发布时间】:2021-02-21 17:50:15
【问题描述】:
在我的 Flutter 项目中测试 Firebase 时,我一直遇到这些 Permission Denied,但我无法弄清楚。我正在使用电子邮件身份验证,它可以正常工作。但是在其他帖子中阅读了这个错误之后,我尝试在我的安全规则中允许 read , write for all :
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
但我仍然得到同样的错误:
W/RepoOperation(24227): setValue at /1_testing failed: DatabaseError: Permission denied
W/RepoOperation(24227): setValue at /2_testing failed: DatabaseError: Permission denied
E/flutter (24227): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(-3, Permission denied, , null)
我发送数据的代码是:
final databaseReference = FirebaseDatabase.instance.reference();
void createRecord(){
databaseReference.child("1_testing").set({
'title': 'It worked once',
'description': 'blablibla'
});
databaseReference.child("2_testing").set({
'title': 'it worked twice',
'description': 'blobloblo'
});
我还重新下载并同步了我的 json 文件 你有什么想法 ?如果答案似乎很明显,这是我第一次尝试这个很抱歉:/
【问题讨论】:
-
您显示的安全规则适用于 Cloud Firestore,而您显示的代码正在访问实时数据库。虽然这两个数据库都是 Firebase 的一部分,但它们是完全独立的,一个的安全规则不适用于另一个。要修复错误,您必须为实时数据库设置规则。有关如何执行此操作的演练,请参阅stackoverflow.com/a/52129163
标签: firebase flutter firebase-realtime-database firebase-authentication