【问题标题】:Cloud Firestore Authentication RegexCloud Firestore 身份验证正则表达式
【发布时间】:2018-06-22 09:35:44
【问题描述】:

是否可以使用正则表达式来识别 Firestore 的用户?

我有一个函数:

function isDeveloper(userId) {
        return isUserAuthenticated(userId) && isCorrectEmail(request.auth.token.email);
}

function isCorrectEmail(email) {
    return email == 'my_email@gmail.com' || email == 'anotherEmail@gmail.com' || email.matches('<regex>');
}

可以对文档进行:

match /{document} {
  allow write: if document.matches('.*@domain[.]com')
}

但这不适用于请求中的电子邮件。有人知道我该怎么做吗?

【问题讨论】:

  • 不应该有正则表达式分隔符吗? email.matches('/.*@domain[.]com/');?

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


【解决方案1】:

这对我有用:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read: if isSignedIn();
      ///allow write: if isSignedIn();
    }
    match /users/{uid} {
        allow read: if isSignedIn() && (isGod() || isAllowedDomain())
      allow create: if isSignedIn() && (isGod() || isAllowedDomain())
      allow update: if isSignedIn() && (isGod() || isAllowedDomain()) && isSelf()
    }
    match /leads/{document} {
        allow read: if isSignedIn();
      allow update: if isSignedIn() && (isCreator() || isManager())
      allow delete: if isCreator();
      allow create: if isSignedIn();
    }

    /// Functions ///
    function existingData() {
        return resource.data
    }
    function incomingData() {
        return request.resource.data
    }
    function isSelf() {
        return request.auth.uid == resource.data.uid
    }
    function isCreator() {
        return request.auth.uid == resource.data.reporterUID
    }
    function isManager() {
        return false
    }
    function isSignedIn() {
            return request.auth.uid != null
    }
    function test () {
        return request.auth.uid == '-----------lm1bdWfhVP9GJw1'
    }
    function isGod () {
        return request.auth.uid == '-----------lm1bdWfhVP9GJw1'
    }
    function isAllowedDomain() {
        return request.auth.token.email_verified == true &&
                   request.auth.token.email.matches(".*@purplescout.se")
    }
  }
}

【讨论】:

    猜你喜欢
    • 2023-03-25
    • 1970-01-01
    • 2020-10-16
    • 2014-02-28
    • 2018-05-02
    • 1970-01-01
    • 2011-02-22
    • 2018-05-08
    • 2018-04-04
    相关资源
    最近更新 更多