Coding Notes

Firebase

By Rae

Firebase

Cloud-based platform

For mobile apps

Notes

  • Script tags in HTML are where you can write JS. add src="filename" to link js file to HTML file.
  • const: appSettings = {databaseURL: "referenceURL"}
  • import { initializeApp } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-app.js"
  • const app = initializeApp(appSettings)
  • import { getDatabase, ref, push } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-database.js"
  • const database = getDatabase(app)
  • const name = ref(database, "what the reference should be called")
  • push(where you want to push it (name), what you want to push)
  • Security Rules
    • using test mode allows anyone with the database reference to view edit and delete the data in your database.
    • the default for testmode is set to a max of 30 days. (how long test mode lasts)
    • to change the max testmode write and read time go to Realtime Database then Rules. If you change them both to true anyone will always be able to read or write in the database.
  • To create a section press the plus next to the url and add a key, then press the plus next to your section name.
  • import { onValue } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-database.js"
  • onValue(where you want to fetch the data from (name), function(snapshot){})
  • onValue runs every time there's a change to the database.
  • to change a key or value in the database just click it and edit it.
  • inmport { remove } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-database.js"
  • <<<<<<< Updated upstream =======
  • Firebase Authentication
    • Used to allow users to sign up with an email and password.
    • Allows users to sign in/out with email and password.
    • Changed auth state
    • Sign in with google
  • Firebase Setup
    • Go to firebase.google.com.
    • Once logged in, select Go to Console which will direct you to console.firebase.google.com.
    • If you have used firebase before you will see all your previous projects.
    • Select Create a new Firebase project.
    • Name your project.
    • Disable or enable analytics/AI as you see fit.
    • Create your project and select "Continue" when it's complete.
    • From your projects page select "Add app" and choose whatever makes sense, I am choosing "Web".
    • On the "Register app" page give your app a nickname, it can be the same as your project name if that makes sense. Now press "Register app".
    • To install this firebase project on your app you can either use npm or a script tag.
  • >>>>>>> Stashed changes

Resources

Firebase
Database
Epoch Converter
converts unix epoch time to real time

Definitions

Reference
Any location inside the database

Questions

  • Is innerHTML bad to use?
  • How come you don't have to import snapshot? or define it?
  • let arrayName = Object.values(snapshot.val())

Opinions