React with Firebase — Setup [Part 1]

Firebase Authentication, Firestore, Storage Setup with React

Anna C.
4 min readSep 23, 2022

This article will be showing you :

  1. How to create a React project with Firebase setting.
  2. How to set the rules of Cloud Firestore and Storage.
  3. How to set Authentication with email and Google Provider.

After setting up these three products provided by Firebase, you will be able to create a CRUD (create, read, update and delete) app with React!

Wait… are you thinking why should you use Firebase as your backend server? Here is an article to discuss about the pros and cons, mentioned,

“ Firebase is fantastic if you want to create something out of nothing in a flash, making it great for rapid prototyping.”

Are you ready? Let’s get started!

Step 1 : Sign up Your Firebase Account

Go to Firebase website, and login you account. (Easy!)

Login page (dashboard)
Create a new project (step 1 of 3)
Create a new project (step 2 of 3)
Create a new project (step 3 of 3)
Waiting…

Step 2 : Set up Authentication Providers

  1. Select Authentication on the left panel.
Panel on the left (authentication)
Get started button

2. Go to Sign-in method and select Email/Password.

Authentication page (sign-in method)
Authentication page (sign-in method with email/password)
Authentication page (sign-in method)

3. Add new provider with Google.

Button (Add new provider)
Authentication page (select google provider)
Authentication page (sign-in method with google provider)
Authentication page (sign-in providers)

Step 3 : Set up Cloud Firestore

  1. Select Firestore Database on the left panel.
Panel on the left (Firestore Database)
Get started button

2. Now we are in Cloud Firestore. The “Data” tab is where your data is located in Cloud Firestore. At this step, we won’t create any data, but you can create your own. To add your new data, you need to start collection first. (see the example below)

Data page in Firestore
Example of a collection

3. To protect and maintain your database and run it properly, we need to add some rules. You can reference the Firebase Docs to set up the rules you need, or see the example in the screenshot provided below.

Set the rules for Cloud Firestore (test mode)
Setting the rules for Cloud Firestore (location near your place)
Example of Cloud Firestore rules

Step 3 : Set up Storage in Firebase

  1. Select Storage on the left panel.
Panel on the left

2. Set the rules for Storage. If you want to know more about Firebase security and rules for Cloud Storage, please see its Docs.

Example of Storage rules

Step 4 : Create a React Project

  1. Register your app, which can be found in Project overview page, and select web option. You also can set up Firebase Hosting meanwhile, but we won’t cover it this time.
Project overview page
App Registration

2. Command Line to create a react app. After the react app is created, following the steps to add Firebase SDK in your project.

$ npx create-react-app [app-name] -use-npm

Firstly, use $ npm install firebase to install Firebase in your project, and create a firebase.config.js at the root of the project with the provdied SDKs.

Firebase SDKs

When you need the database, you just need to import the db from the config file. For example, import { db } from “../firebase.config”.

OK! We are all done! I know that Hosting is another important part…I’ll cover that a bit later. :>

Finally, I’d like to thank Brady’s React front to end 2022 on Udemy, which has helped me explore and obtain more knowledge in React and Firebase.

--

--