Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android firestore:让用户只更新、删除自己的数据_Android_Firebase_Firebase Authentication_Google Cloud Firestore_Firebase Security - Fatal编程技术网

Android firestore:让用户只更新、删除自己的数据

Android firestore:让用户只更新、删除自己的数据,android,firebase,firebase-authentication,google-cloud-firestore,firebase-security,Android,Firebase,Firebase Authentication,Google Cloud Firestore,Firebase Security,以下是我当前的安全规则: service cloud.firestore { match /databases/{database}/documents { match /tournaments/{tournament=**} { allow update, delete: if request.auth.uid == resource.data.author; allow create: if request.auth.uid != null; allow re

以下是我当前的安全规则:

service cloud.firestore {
  match /databases/{database}/documents {
  match /tournaments/{tournament=**} {
    allow update, delete: if request.auth.uid == resource.data.author;
    allow create: if request.auth.uid != null;
    allow read: if true;
  }
  }
}
一切正常,只有更新或删除由于“缺少或权限不足”而不起作用

这是我的代码

            mDocRef
                .update(key, score)
                .addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                        Log.d(TAG, "DocumentSnapshot successfully updated!");
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Log.w(TAG, "Error updating document", e);
                    }
                });
需要注意的一些事项:

  • 用户在整个过程中通过firebase登录
  • 我尝试使用.where(“author”,“==”,user.uid),但出现了“无法解析方法”错误

谢谢你的帮助

我将firebase用户的ID添加到为获得想要的结果而创建的每个文档中

 tournamentData.put("author", user.getUid());
 data.put("author", user.getUid());

我查看了文档,这些是您要查找的规则:

match /users/{userId} {
  allow read, update, delete: if request.auth.uid == userId;
  allow create: if request.auth.uid != null;
}
和文档链接作为参考:

match /users/{userId} {
  allow read, update, delete: if request.auth.uid == userId;
  allow create: if request.auth.uid != null;
}