Firebase 使用用户';Firestore规则中的电子邮件是什么?

Firebase 使用用户';Firestore规则中的电子邮件是什么?,firebase,google-cloud-platform,google-cloud-firestore,firebase-security,rules,Firebase,Google Cloud Platform,Google Cloud Firestore,Firebase Security,Rules,在firestore数据库中,我仅使用电子邮件作为身份验证。数据库具有以下结构: companies jobs users 为了可读性(以及为了客户的安心),我使用电子邮件地址作为用户集合的文档ID。用户文档如下所示: document id: tbogard@gmail.com fields name_first: Terry name_last: Bogard jobs_read: ["job_A"] jobs_readwrite: ["job_B, job_C"] 当我

在firestore数据库中,我仅使用电子邮件作为身份验证。数据库具有以下结构:

companies
jobs
users
为了可读性(以及为了客户的安心),我使用电子邮件地址作为
用户
集合的文档ID。
用户
文档如下所示:

document id: tbogard@gmail.com
fields
  name_first: Terry
  name_last: Bogard
  jobs_read: ["job_A"]
  jobs_readwrite: ["job_B, job_C"]
当我试图在规则中获取请求令牌时,它会给我错误(搜索***):


我猜
request.auth.token.email
返回的是可选的吗?我在中找不到任何解释函数
get/exists
(需要路径)如何处理此问题的内容。有没有办法让每个用户的Firestore UID成为电子邮件地址而不是随机字符串,或者我可以通过某种方式修正这些规则?

但是,您无法更改Firestore自动生成的UID,我建议你阅读一些有助于你修正规则的文章。你偶然发现了这个问题吗?为了便于读取和返回数据,我以同样的方式构建了我的数据,但我需要确保用户只能读取/写入他们自己的数据。
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {

    // Helper functions
    function userExists(){ 
      // *** Function not found error: Name: [exists]. ***
      return exists(/databases/$(database)/documents/users/$(request.auth.token.email));
    }
    function userData(){
      // *** Function [get] called with malformed path: /databases/(default)/documents/users/ ***
      return get(/databases/$(database)/documents/users/$(request.auth.token.email)).data;
    }

    // For now, let's keep it simple, and enforce the User read/readwrite rules on Jobs.
    match /jobs/{jobId}{
      allow read: if userExists() && (jobId in userData().jobs_read || jobId in userData().jobs_readwrite);
      allow write: if userExists() && jobId in userData().jobs_readwrite;
    }

    // Only allow Users to see their own profile and companies they belong to.
    match /companies/{companyId}{
      allow read: if userExists() && userData().email in resource.data.employees;
      allow write: if false;
    }
    match /users/{userId}{
      allow read: if userExists() && userData().email == resource.data.email;
      allow write: if false;
    }
  }
}