Firebase Notes

Firebase Setup Notes


Last Updated: February 14, 2023 by Pepe Sandoval



Want to show support?

If you find the information in this page useful and want to show your support, you can make a donation

Use PayPal

This will help me create more stuff and fix the existent content...


Firebase Course

  • Firebase provides BaaS (Back-End as a Service), services:
    • Cloud Firestore: Realtime database, NoSQL document database, easily configurable security rules
    • Hosting: SSL automatically provisioned, deploy from CLI
    • Storage: you can store any type of file (images, videos, text documents, etc), it can handle large file, easily configurable security rules to access files
    • Auth: email/password auth, OAuth Authentication (using of existing platform like Google, Twitter, FaceBook, Github, etc),

Firebase Basic setup

Create a Firebase Project

  1. Go to Firebase console (The Firebase Console: refers to the web page GUI where you can setup a project in Firebase and configure it)
  2. Click on "Add Project" Button, give it a name and create your project (You can leave the defaults when prompt for other stuff)
    • Create Project

Add a web app to your project

  1. Go to project settings, scroll to the bottom and click on the web button, follow the prompts to generate the Firebase configuration
    • Config Project
  2. (Optional) install Firebase CLI, this is recommended if you plan use Firebase as a hosting service and deploy your web app on Firebase
    1. First install nodejs and npm with curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - && sudo apt-get install -y nodejs (check NodeSource documentation for more info about installation)
    2. Check Node version npm version && node -v
    3. Install Firebase sudo npm install -g firebase-tools (This command takes a while be patient here)
  3. (Optional) To deploy:
    1. Run firebase login and login with your Google credentials
      • If prompted for data collection you can answer n
    2. Run firebase init on the app's root directory
      • When prompted for what Firbase CLI you wan to set up, select: Hosting: Configure and deploy Firebase Hosting sites
      • When prompted to associate this project directory with a Firebase project, select: Use an existing project and select your firebase project
      • When prompted for what to use as public directory, type: ./ (This tells firebase to look for index.html here)
      • When prompted to configure a single-page app, select N and also select N when prompted to ovewrite index.html
    3. Put your static files (HTML, CSS, JS) in your app's deploy directory then on your app's root directory run firebase deploy

To uninstall use sudo npm uninstall -g firebase-tools and remove sudo rm -rf /usr/lib/node_modules/firebase-tools /usr/local/bin/firebase

Create Cloud Firestore Database

  1. On the Right side panel look for the option that mentions Cloud Firestore and click on it
  2. Click on Create database
  3. When asked for Security rules make sure to start in test mode (This mode allows anyone to read-write the DB and expires after 30 days)
  4. Leave the default location (if you have setup a previous service that requires location you cannot change this)
  • Create DB
  1. (Optional) Modify rules, for example to allow ANYBODY to read-write the database
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

Setup Firebase storage

  1. On the Right side panel look for the option that mentions Storage and click on it
  2. Click on Get Started
  3. When asked for Security rules make sure to start in test mode (This mode allows anyone to read-write the storage and expires after 30 days)
  4. Leave the default location (if you have setup a previous service that requires location you cannot change this)
  • Create Storage
  1. (Optional) Modify rules, for example to allow ANYBODY to read-write the storage
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if true
    }
  }
}

Firebase Admin SDK

  • Firebase Admin SDK is the official library developed by Google that allow users to integrate Firebase with different programming languages (Java, C#, Python, etc.) this means it allows you do all the things you do on the web console programmatically like operations on the firbase storage and databases

Python Firebase Admin SDK Installation

  1. (Optional/Recommended) create a venv because firebase-admin has many Google dependencies
  2. Install (Go to Add the SDK for more install info)
    • sudo python -m pip install firebase-admin
  3. Create a private key JSON
    1. Go to Project Settings and then to Service Accounts
    2. On the Firebase Admin SDK select Python and click on Generate new private key
    3. Save the generate .JSON file (you can change the name to just key.json)
  • Create key
  1. On your Python project create an app object using the JSON file key
import firebase_admin
from firebase_admin import credentials

key_path = "PATH_TO_JSON_FILE_HERE/key.json"
cred = credentials.Certificate(key_path)
app = firebase_admin.initialize_app(cred)
print(app)

Pyrebase4 is an alternative library to interface with Firebase but this is not built by Google

Firebase Authentication

  • Authentication in Fireabase allows you to manage users for login and sign up purposes

Setup Firebase Authentication

  1. On the Right side panel look for the option that mentions Authentication and click on it
  2. Click on Get Started
  3. On the Sign-in method tab select Email/Password to Enable it and click the Save button
  • Create key
Want to show support?

If you find the information in this page useful and want to show your support, you can make a donation

Use PayPal

This will help me create more stuff and fix the existent content...