我完成了应用程序的制作,正在实现安全规则。我目前正在尝试验证银行中是否存在用户,如果他存在,他将能够读取和写入特定路径。我正在使用Firestore:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents{
match /Usuarios/{documentID} {
allow read, update, delete: if request.auth.uid != null && request.auth.uid == documentID;
allow create: if request.auth.uid != null;
match /Manejo/{manejoID} {
allow write, read: if exists(/databases/$(database)/documents/$(request.auth.uid)); // The id is never exist... even when it does exist in my database, this operation simply DOES NOT WORK despite the document with the Uid existing in the database
}
}
}
第1版:
match /Manejo/{manejoID} {
allow write, read: if true;
}
这种情况也不起作用。。。
您需要声明要在哪个集合中使用docId == userId
检查文档的存在
带
allow write, read: if exists(/databases/$(database)/documents/$(request.auth.uid));
你没有申报集合。
查看文档中的以下示例,该示例检查users
集合中是否存在docId == userId
的文档。查看如何在$(database)/documents
之后添加/users/
。
allow create: if request.auth != null && exists(/databases/$(database)/documents/users/$(request.auth.uid))
我想检查Usuarios
集合中是否存在文档。如果这个假设是正确的,请执行以下操作:
allow write, read: if exists(/databases/$(database)/documents/Usuarios/$(request.auth.uid));
请注意,您可能对这篇Firebase博客文章感兴趣。