Can't write to Firestore without insecure security rules

How do we set the rules on cloud store so that react studio can connect can write with out having to have the Firestore db open to the world?

We tried

rules_version = ‘2’;
2
service cloud.firestore {
3
match /databases/{database}/documents {
4
match /{document=**} {
5
allow read, write: if request.auth != null;
6
}
7
}
8
}
But react studio could not connect with the Firestore plugin

thanks, team.

At the moment you cant, you need to keep the development database rules open when loading the example data (basically the structure of the data model) into Data sheets. You can simply change the Firebase config to point to live database when you generate the code.

If someone is interested in developing the Firebase plugin then one could probably add a login function to the plugin settings which would allow studio user to authenticate and load data as the end user.

Thanks! Where would we access the source code for the plugin to make that functionality?

Also, if it’s not too much of a deviation from the above topic, how do I write a query to limit the data that React Studio pulls into a sheet? I’m told it involves NOSQL, but that’s not a language with which I’m familiar.

To edit the plugin you would have to go to “Plugins” – “Edit plugin” in the menu and then select “Firebase Login” to modify the code:

If you want to limit the data for the dataSheet you have to write in the Query box within the dataSheet options the code “limit([Number you establish])”

Captura de pantalla 2021-03-11 a las 23.38.36

I hope that helps!

Aces! Thanks, Pedro!! What query would I use to limit the queries to only (say) the ones for which the value of a specified field equal the value in a specified data slot. The use-case here is that we’re going to have files (characters in a game), each associated with a user by their email address. In production, we could very well have thousands of files, so we only want to pull in a given user’s files and no one else’s.

In the screen capture that I used in the previous message you can see that I established the limit query according to a dataSlot that I named “ds_limitQuery” and I use it to control the number of documents to be shown. Then I just put a picker to change the value in the dataSlot. Not complicated at all. I guess you could get more complex things. So first you create a dataSlot with the name you choose and then you use the “limit($slot(”[nameOfTheDataSlot]"))

Aces! Thanks, Pedro!

1 Like

Make sure you read the limitations of queries in Firebase from their docs. It is not a relational database so many of the standard SQL queries are not possible.

Update: We’ve got both a test and a prod database in Firebase. However, having both connected to the React Studio app always breaks it (attached.).

Hi, thats actually a bug which causes code engine to write some code with duplicate name. I think no one has had two different Firebase plugin instances in one project because we haven’t got report from this.

Anyway I suggest you to simply change the Firebase config in plugin settings when you want to toggle between QA-database and Production database. Its much easier for you because then you don’t have to go trough all Data sheets and change the plugin setting.

1 Like