Introduction into reading and writing data into a firebase database using React.
-
Create vite application
yarn create vite firebase-react-demo --template react-ts
-
Create firebase application
-
Login to Firebase
-
Create new application (calling it firebase-react-demo)
-
Add a Web Connection to Firebase (calling it react-web)
- Did not enable web hosting for this project
-
Enable Realtime Database (for reading and writing to json store)
-
Enable Storage (for adding files)
-
-
Install Firebase into application
yarn add firebase
-
Configuring the webapp
-
Setup firebase.service.ts
-
Add .env file with all variables
-
-
Choosing database provider
-
Disabling reading / writing
rules_version = '2'; service firebase.storage { match /b/{bucket}/o { match /{allPaths=**} { allow read, write: if request.time < timestamp.date(2022, 6, 8); } } }
{ "rules": { ".read": true, // 2022-6-7 ".write": true, // 2022-6-7 } }
-
Running the emulator
-
Before installing the Emulator Suite you will need:
-
Node.js version 8.0 or higher
-
Java version 1.8 or higher
choco install oraclejdk
npm i -g firebase-tools
After installation, run the initialize (will setup everything you need to run the emulators)
firebase init
firebase init emulators
Running the emulators
firebase emulators:start
-