Firebase Angular应用程序无法访问Firestore数据库?

Firebase Angular应用程序无法访问Firestore数据库?,firebase,google-cloud-firestore,firebase-security,Firebase,Google Cloud Firestore,Firebase Security,我有一个angular应用程序,带有正确配置了apiKey的firebaseConfig。当应用程序初始化时,它应该去相应的Firestore并在那里收集电子邮件地址,并将其存储起来,以供以后的用户身份验证。问题是,除非有用户登录,否则应用程序无法执行此操作。这让人感到困惑,因为我认为该应用程序可以访问Firestore数据库,而无需经过身份验证。我能想到的唯一解决办法是设置Firestore规则以允许全局读取访问。这样,当应用程序启动时,它保证可以访问数据库和其中的电子邮件 我在这里遗漏了什么

我有一个angular应用程序,带有正确配置了apiKey的firebaseConfig。当应用程序初始化时,它应该去相应的Firestore并在那里收集电子邮件地址,并将其存储起来,以供以后的用户身份验证。问题是,除非有用户登录,否则应用程序无法执行此操作。这让人感到困惑,因为我认为该应用程序可以访问Firestore数据库,而无需经过身份验证。我能想到的唯一解决办法是设置Firestore规则以允许全局读取访问。这样,当应用程序启动时,它保证可以访问数据库和其中的电子邮件


我在这里遗漏了什么?

你没有遗漏任何东西。如果您希望用户能够查询Firestore集合而无需提前进行身份验证,则该集合将需要完全的公共读取访问权限。无法编写安全规则来限制特定应用程序或网站对数据库的访问。

您不会遗漏任何内容。如果您希望用户能够查询Firestore集合而无需提前进行身份验证,则该集合将需要完全的公共读取访问权限。无法编写将数据库访问限制为特定应用程序或网站的安全规则。

如果您的安全规则如下所示:

// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth.uid != null;
    }
  }
}
然后,只有用户经过身份验证,他们才能访问数据。您可以将规则更改为以下内容:

// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth.uid != null;
    }

        match /{collectionName}/{docId} {
      allow read: if collectionName == 'emailCollection';
    }
  }
}
这样,如果用户经过身份验证,则他们可以访问所有文档;如果集合名称等于
emailCollection
,则未经身份验证的用户可以访问它


如果您的安全规则如下所示:

// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth.uid != null;
    }
  }
}
然后,只有用户经过身份验证,他们才能访问数据。您可以将规则更改为以下内容:

// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth.uid != null;
    }

        match /{collectionName}/{docId} {
      allow read: if collectionName == 'emailCollection';
    }
  }
}
这样,如果用户经过身份验证,则他们可以访问所有文档;如果集合名称等于
emailCollection
,则未经身份验证的用户可以访问它


那么您打算在客户端存储所有电子邮件以进行身份验证?这听起来很不安全,你会向任何访问你网站的人公开人们的电子邮件。我对这一点很陌生,完全接受建议!那么你打算在客户端存储所有电子邮件以进行身份验证?这听起来很不安全,你会向任何访问你网站的人公开人们的电子邮件。我对这一点很陌生,完全接受建议!