Skip to content
Advertisement

Firestore denying permission to create/push collection

I am new to firebase / firestore and am trying to create a new collection upon login and authenticating a user, on client side and using React. I read a few other articles here and I set the db rules to true for both read and write, but yet, I keep getting an error on the Firestore db, while it works perfectly if I initialise a Realtime Database. Also, I can get and read data, but not write it.

The code I have is pretty simple:

JavaScript

and my rules are set as such:

JavaScript

Does anyone have an idea of how I can do this?

Advertisement

Answer

First off, double check that you’re including the Firestore SDK in your code. Then…you’re using RTDB syntax to try to add a document to Firestore in createUserRoles. You need to switch it to Firestore’s syntax:

JavaScript

Not also that reads and writes with Firestore (just like RTDB) are asynchronous so you need to use async/await (like I added) or then/catch promises.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement