flutter - Firestore 安全规则 Flutter 应用拒绝权限
问题描述
我目前正在尝试将我的 Firebase 后端连接到我的 Flutter 应用程序。get()
在向 Firestore创建一个简单的请求后,我每次都会遇到相同的错误:
[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 进行状态管理。
解决方案
@DougStevenson 谢谢你!原来我试图从我的 Firebase 控制台中的错误项目中提取数据。奇怪的场景,但你的评论鼓励我跳出框框思考。
原因是在我的 Runner 文件中放置了来自不同项目的错误 GoogleService-Info.plist 文件。
推荐阅读
- ios - 未调用方法“应用程序:openURL:选项:”
- c# - PictureBox 悬停在参数上是无效的问题
- corda - 如何平衡 Corda DB 和 Flow Executions?
- flutter - SingleChildScrollView 不保持滚动位置
- mongodb - 如何纠正 Mongodb 中的文档验证失败?
- c# - ASP.Net Core API 将模型 int Id 绑定到自定义 Id 对象
- c# - UWP:如何从内存中删除图像?
- javascript - 使用jquery从第一次单击到第二次单击检查多个复选框
- python - Python 测试文件类型和标识符是什么?
- c# - 无法从程序集“mscorlib,版本=4.0.0.0”加载类型“System.Security.Cryptography.SHA256Managed”