我正在分析 firebase cloud firestore 的入门指南。这是针对 Android 应用程序的。 https://firebase.google.com/docs/firestore/security/get-started
我需要保存和读取每个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
的字段中,您可以执行以下操作:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read: if request.auth.uid != null && resource.data.createdBy == request.auth.uid;
allow write: ....
}
}
}