Allow unregistered users to query Firestore to check if an E-Mail already exists

只谈情不闲聊 提交于 2021-02-04 08:36:45

问题


Right now, in my Firestore rules only registered users have read / write access to my project. However, I also want to verify in my registration process if an E-Mail already exists, which means also anonymous user have access to my "users" data.

I am unsure how this is compliant from a security perspective. Should I create something like a "emails" collection and duplicate all E-Mail addresses here and allow anonymous users to query this?


回答1:


Yup, that is indeed the typical approach. Duplicate the data that you want anonymously accessible into a separate collection, and grant broader access restrictions there.

In the rules for that collection of email addresses you will typically use granular rules that allow reading each specific document, but to disallow listing all documents. Something like:

match /emails/{email} {
  // Applies to single document read requests
  allow get: if <condition>;

  // Applies to queries and collection read requests
  allow list: if false;
}

This means that once the user has typed a specific email address, you can check if a document exists for that email address. But they can't just get all documents from the collection to scrape your user base.



来源:https://stackoverflow.com/questions/59766574/allow-unregistered-users-to-query-firestore-to-check-if-an-e-mail-already-exists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!