【问题标题】:security rules for grouped collection and inner collection分组集合和内部集合的安全规则
【发布时间】:2021-09-15 09:04:01
【问题描述】:

我正在尝试使用 Firebase Firestore 为一个集合中的所有集合设置 Firebase 安全规则。 我有一个名为game_lookup 的集合,里面有很多命名的文件,一个是比赛,其他的都在那里。而且它们都有很多内层子集合。

喜欢

/game_lookup/arcade/level_-6NVwtc0cp-/1

我想为比赛设置不同的规则,其余的规则相同。

对于我定义的比赛

 match /game_lookup/{document} {
    allow read: if isAuthenticated();

  match /tournament/{document} {
    allow read: if isAuthenticated();
  }

  match /tournament_players_list/{document} {
    allow read, write: if isAuthenticated();
   
    match /allusersPostion/{document} {
      allow read, write : if false;
    }
    
    match /percentile/{document} {
      allow read, write : if false;
    }
  }

  match /tournament_template/{document} {
    allow read, write : if false;
  }
}

现在这个 /game_lookup/arcade/master/,

/game_lookup/arcade/level_-6NVwtc0cp-/1

我无法访问它。

编辑

我如何只允许那些被授权/game_lookup/contest/tournament_players_list/0Bqbujy16qOYa8YAIbQT/joined/{userId}的用户

我试过了

   match /joined/{document} {
        allow read, create, update: if isAuthenticated() && request.auth.uid == userId;
    }

不工作

【问题讨论】:

    标签: firebase google-cloud-firestore firebase-security


    【解决方案1】:

    您无法访问/game_lookup/arcade/master/,因为您尚未为master 子集合定义任何规则。所以定义这样的规则:

    match /game_lookup/{document} {
      allow read: if isAuthenticated();
      
      match /master/{document} {
        allow read: if isAuthenticated();
      }
      // ... other rules
    
      // For "/game_lookup/arcade/level_-6NVwtc0cp-/1', you also define as below
      match /level_-6NVwtc0cp-/{document} {
        // define rules.
        // rules here will define access for '/game_lookup/arcade/level_-6NVwtc0cp-/1'
      }
    }
    
    // **EDIT**
    // below works on playground but have not been tested on physical device.
    // you can add a more specific rule like this to determine permissions on
    // game_lookup/master documents.
    match /game_lookup/master {
      allow read: if isAuthenticated();
      // this should determine access for master documents
    }
    // with this, you can define seperate rules for collection/documents 
    that only exist in master documents (per our chat in the comments)
    

    【讨论】:

    • 实际上,这个大师系列存在于街机,但可能不存在于决斗,即使这需要单独定义?
    • 是的,你需要单独定义所有的。
    • 您可以查看我的更新答案...match /game_lookup/master{// this should determine access for master documents} 在操场上工作,但尚未在物理设备上测试
    • 我认为可能会有一个答案阻止我多次写相同的内容。
    • @cakePHP 如果这回答了您的问题,请告诉我们?
    猜你喜欢
    • 2020-07-01
    • 2020-02-02
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    • 2020-12-28
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多