【发布时间】:2021-02-13 00:35:04
【问题描述】:
我目前正在尝试将我的 Firebase 后端连接到我的 Flutter 应用。在向 Firestore 创建一个简单的 get() 请求后,我每次都遇到相同的错误:
[cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.
我尝试过的安全规则:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.time < timestamp.date(2020, 11, 30);
}
}
}
allow read, write;
allow read, write: if true;
allow read, write: if request.auth.uid != null;
allow read, write: if request.auth != null;
allow read, write: if auth != null ;
我确实在阳光下尝试了所有方法,但在读取或写入我的数据库方面没有成功,这让我相信问题出在我的代码中。我已检查以确保 Firebase 已正确初始化,Firebase Core 和 Firebase Firestore 也已正确初始化。
这是 Firebase 问题还是需要执行对 Firestore 的调用的特定方式?
获取请求:
fetchChatMessages() async {
var messageSnapShots =
await FirebaseFirestore.instance.collection('topicofday').get();
print('Messages: $messageSnapShots');
}
}
初始化 Firebase:
class MyApp extends StatelessWidget {
final Future<FirebaseApp> _initialization = Firebase.initializeApp();
@override
FutureBuilder build(BuildContext context) {
return FutureBuilder(
future: _initialization,
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return buildMaterialApp(context);
}
return Center(
child: Container(
child: CircularProgressIndicator(
backgroundColor: Theme.of(context).primaryColor,
),
),
);
},
);
}
附加信息:
不确定这是否会影响请求,但我正在使用 Provider 进行状态管理。
【问题讨论】:
-
您究竟在做什么来更新您的规则?编辑问题以完成您所采取的步骤。
-
你指的是更新Firestore中的规则吗??就像对规则进行适当的更改然后发布一样?
-
是的,您可能根本没有真正发布新规则,或者您可能正在其他项目中发布规则。
-
为什么要设置这个条件?允许读、写: if request.time stackoverflow.com/questions/52422047/…
-
你能分享你的解决方案作为这篇文章的答案吗?此信息可以帮助遇到类似情况的其他用户。
标签: flutter google-cloud-firestore firebase-security