代码之家  ›  专栏  ›  技术社区  ›  pedrommuller

Restric firesotre CRUD提供给特定域内的用户

  •  0
  • pedrommuller  · 技术社区  · 6 年前

    我正在尝试在Firestore中创建一个规则,该规则将属于特定域的用户的所有CRUD操作都限制在使用范围内,我的问题是在规则上下文中似乎不存在contains子句。

    这是我的规则:

    service cloud.firestore {
      match /databases/{database}/documents {
        match /{document=**} {
          allow read, write: if isUserAndSignedIn();
        }
      }
    
      function isUserAndSignedIn(){
        return request.auth != null && request.auth.token.email.contains('domain.com')
      }
    }
    

    我得到的错误是: 错误:模拟器规则第[9]行,第[36]列。找不到函数错误:名称:[包含]。

    请求授权令牌.电子邮件.endsWith('域名.com')

    1 回复  |  直到 4 年前
        1
  •  3
  •   Doug Stevenson    6 年前

    request.auth.token.email 是一根弦,而且 according to the reference docs matches

    'user@domain.com'.matches('.*@domain[.]com') == true
    

    你应该能够适应你的情况:

    return request.auth != null && request.auth.token.email.matches('.*@domain[.]com')