尝试仅向使用 firestore 规则发布照片的用户显示应用中的照片

Trying to display photos in app only to user that posted them using firestore rules

我有一个应用程序,用户可以登录该应用程序并拍摄照片并将其添加到供稿中。我使用 firestore 作为数据库。

现在所有用户都可以看到其他所有用户的照片以及他们自己的照片。我希望只有登录的用户才能查看自己的照片。 另一个论坛中的一位用户建议我使用 firestore 规则来设置该控件,但我在实施正确代码时遇到了问题。

我通读了有关 firestore 的文档,并尝试按照他们所拥有的方式实现代码,但没有成功。以下是我的数据库信息和我当前的规则(不起作用)谢谢。

数据库:

service cloud.firestore {

  match /databases/{database}/documents { 
  
  match /{document=**}{

      allow read, write: if request.auth != null && request.auth.uid == 'byId';

      }

  }

我希望此代码将用户的 uid 与 byId 字段(应该相同)进行比较,如果为真,则允许他们读写自己的数据

我还有一个身份验证页面,其中 uid == byId

这个检查request.auth.uid == 'byId' 检查当前用户的UID 是否是字面上的byId。如果要检查 UID 是否与文档中 byId 字段的 ht 值相同,请使用:

if request.auth != null && request.auth.uid == request.resource.data.byId;

我还建议查看 securing document access 上的 Firebase 文档。