Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.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 用户级firebase云firestore中的身份验证问题_Android_Firebase_Google Cloud Firestore - Fatal编程技术网

Android 用户级firebase云firestore中的身份验证问题

Android 用户级firebase云firestore中的身份验证问题,android,firebase,google-cloud-firestore,Android,Firebase,Google Cloud Firestore,我正在分析firebase cloud firestore的入门指南。这是一款android应用程序。 // Allow read/write access on all documents to any user signed in to the application service cloud.firestore { match /databases/{database}/documents { match /{document=**} {

我正在分析firebase cloud firestore的入门指南。这是一款android应用程序。

// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
    match /databases/{database}/documents {
        match /{document=**} {
            allow read, write: if request.auth.uid != null;
        }
    }
}
我需要保存和读取每个android设备的用户数据,以备份一些数据。firebase cloud firestore的文档显示了以下用于访问所有用户数据的代码。但是我想将用户数据限制为私有数据,以便只有保存它的用户才能访问它。请告知如何继续访问/身份验证过程

// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
    match /databases/{database}/documents {
        match /{document=**} {
            allow read, write: if request.auth.uid != null;
        }
    }
}

如果将保存文档的用户的uid存储在名为(例如)
createdBy
的字段中,则可以执行以下操作:

// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
    match /databases/{database}/documents {
        match /{document=**} {
            allow read, write: if request.auth.uid != null;
        }
    }
}
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read: if request.auth.uid != null && resource.data.createdBy == request.auth.uid;
      allow write: .... 
    }
  }
}

如果将保存文档的用户的uid存储在名为(例如)
createdBy
的字段中,则可以执行以下操作:

// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
    match /databases/{database}/documents {
        match /{document=**} {
            allow read, write: if request.auth.uid != null;
        }
    }
}
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read: if request.auth.uid != null && resource.data.createdBy == request.auth.uid;
      allow write: .... 
    }
  }
}

控制台中的数据是否仍然可见?我理解您的回答。。它只对造物主可见吗?是的。如果在创建时将作者的uid存储在字段
createdBy
中,则
允许读取的规则将仅限制作者的读取权限。您可以添加规则以避免在创建后对此字段进行任何修改(例如,在
允许更新
规则中)。我建议你看关于这个主题的官方视频:。如果你认为我的回答有帮助,你可以投票接受。谢谢.最后一个问题。。我们在控制台中是否仍然可以看到所有人的数据?我不希望在控制台中看到用户数据。您提供的代码段是否会解决这一问题?在
request.auth.uid
中,您将在身份验证部分获得您在Firebase控制台中看到的用户ID。有关更多详细信息,请参阅。除了你的接受,别忘了对我的答案投赞成票!谢谢控制台中的数据是否仍然可见?我理解您的回答。。它只对造物主可见吗?是的。如果在创建时将作者的uid存储在字段
createdBy
中,则
允许读取的规则将仅限制作者的读取权限。您可以添加规则以避免在创建后对此字段进行任何修改(例如,在
允许更新
规则中)。我建议你看关于这个主题的官方视频:。如果你认为我的回答有帮助,你可以投票接受。谢谢.最后一个问题。。我们在控制台中是否仍然可以看到所有人的数据?我不希望在控制台中看到用户数据。您提供的代码段是否会解决这一问题?在
request.auth.uid
中,您将在身份验证部分获得您在Firebase控制台中看到的用户ID。有关更多详细信息,请参阅。除了你的接受,别忘了对我的答案投赞成票!谢谢