Flutter 代码=权限\被拒绝,描述=权限缺失或不足,原因=空

Flutter 代码=权限\被拒绝,描述=权限缺失或不足,原因=空,flutter,firebase-security,Flutter,Firebase Security,我无法在有规则的情况下将数据读/写到firestore 我可以访问我的数据并对其进行操作,无需设置规则,如下所示: match /{document=**} { allow read, write: if true; } 但我得到了“权限被拒绝”错误与以下规则 match /{document=**} { allow read, write: if request.auth.uid != null; } 这是我的省道代码: if (uid == null) { user = aw

我无法在有规则的情况下将数据读/写到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,
});
  • 我能够使用firebase模拟器通过身份验证进行读/写
  • 我是否可以使用cloud\u firestore软件包打印从dart发送到firebase的实际请求

    编辑2

  • Firestore.instance正在使用规则
  • 使用“配置”将Firebaseapp配置为我的特定应用,选项无效

  • 有关于为什么会发生这种情况的帮助吗?

    将规则更改为允许读、写:if request.auth=无效

    如果您想允许任何人上传文档,只需将规则更改为如下

    allow read, write;
    
    如果您希望仅允许经过身份验证的用户允许将文件或文档上载到firebase,请将规则更改为

    allow read, write: if request.auth != null;
    

    我尝试了这个解决方案,但没有解决问题。但我仍然面临着同样的错误——“失败:状态{code=PERMISSION\u DENIED,description=权限缺失或不足,cause=null}”检查您的登录我让用户登录,因为我的完整错误是:W/Firestore(28828):(21.1.1)[Firestore]:侦听查询(用户/{userid}/按名称排序位置)失败:状态{code=PERMISSION\u DENIED,description=Missing或permissions不足,cause=null}.{userid}在该错误中是实际的userid值。请使用Firebase规则模拟器(在控制台中)。在那里,您还可以模拟登录用户。通过这种方式,您可以确保它在应用程序中不是身份验证。顺便说一句:request.Auth.uid!=null完全可以。我运行了firebase模拟器。它允许我通过身份验证进行读/写。为了确保我有一个经过身份验证的用户,我将代码更改为:user u=wait a.onauthstateed.first;if(u!=null){….}我的代码进入if块,这意味着firebase用户在我的代码中的该点进行了身份验证。可以肯定,使用request.auth.uid!=null与作者一样没有任何错误
    allow read, write: if request.auth != null;