0

I want to know what should be the rules in firebase to implement this? Suppose I just want to authenticate if the user email is thisIsExampleEmail@gmail.com and no other users can read and write the data of firebase firestore.

Firebase Rules

allow read, write:if request;

what else to add in this to implement the above

Thanks!

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
Nimish
  • 35
  • 8
  • Where do you want to read the email from? Or do you just want to hard code that single email? The email of user trying to read/write data can be found in `request.auth` object. – Dharmaraj Nov 09 '21 at 12:06
  • Does this answer your question? [How do I lock down Firebase Database to any user from a specific (email) domain?](https://stackoverflow.com/questions/36943350/how-do-i-lock-down-firebase-database-to-any-user-from-a-specific-email-domain) – Kundan Nov 09 '21 at 13:13
  • Thanks, @Dharmaraj but i have already used it, this is not working. I am not able to read my data – Nimish Nov 09 '21 at 13:21
  • I'm unsure what rules you've tried. Can you update your question with the same ? – Dharmaraj Nov 09 '21 at 13:24
  • @Kundan I looked into it but I think the database used there is not cloud firestore but there it's real-time database. – Nimish Nov 09 '21 at 13:25
  • @Dharmaraj this is the line of code I tried - `allow read, write:if request.auth.email == "myemail@gmail.com";` – Nimish Nov 09 '21 at 13:27
  • 1
    It's `request.auth.token.email` and not `request.auth.email` – Dharmaraj Nov 09 '21 at 13:29
  • @Dharmaraj Thanks its working now. But to read the data I have to refresh the page again. Do you know why is this happening? – Nimish Nov 09 '21 at 13:36
  • Unsure what page you are referring to. I'd recommend posting a new question if that's not related with this question. – Dharmaraj Nov 09 '21 at 13:38
  • I mean the website page on which I am using this authentication (using reactjs). – Nimish Nov 09 '21 at 13:50

0 Answers0