【发布时间】:2020-02-11 14:26:53
【问题描述】:
我无法在有规则的情况下将数据读/写到 Firestore。
我可以访问我的数据并对其进行操作,而无需设置如下所示的规则:
match /{document=**} {
allow read, write: if true;
}
但我收到以下规则的“权限被拒绝”错误。
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
这是我的飞镖代码:
if (uid == null) {
user = await a.currentUser();
uid = user.uid;
}
DocumentReference docRef = firestore.collection('users').document(uid);
CollectionReference locations = docRef.collection('locations');
await locations.document().setData(<String, double>{
'latitude': latitude,
'longitude': longitude,
});
我可以想到这个请求失败的两种情况:
- request.auth.uid == null。但我有一个用户在此查询之前使用 firebase auth 登录。
- 我的安全规则和查询不匹配。
请帮我调试这个问题。
编辑 1:
- 我在我的 firebase 查询期间对用户进行了身份验证,因为我将代码更改为仅在用户通过以下身份验证时才输入:
User u = await a.onAuthStateChanged.first;
if (u != null) {....}
- 我能够使用 Firebase 模拟器通过身份验证进行读/写。
我是否可以使用 cloud_firestore 包打印从 dart 发送到 firebase 的实际请求?
编辑 2
- Firestore.instance 正在使用规则
- Firebaseapp 使用 configure 配置到我的特定应用,选项不起作用。
对为什么会发生这种情况有任何帮助吗?
【问题讨论】: