Table of Contents
Introduction
Setup
Setup a Project & Database
David demonstrates how to quickly set up a Firebase project by configuring a Firebase App, which includes a JavaScript SDK and a Firebase CLI. A Student's question regarding if the initialize app config is different in an SSR library such as Next.js is also covered in this segment.Working with Firestore Data
David walks through connecting to a Firestore database by pulling in markdown that has been converted into HTML and discusses how working with Firestore data compares to using SQL. Setting a document, deleting a document, and receiving the results in a callback are covered in this segment.Firebase Authentication
David discusses implementing Firebase authentication using the Anonymous authentication provider, which can also provide guest authentication. Firebase Authentication is a fully managed authentication system for signing in and managing users without needing a designated server.Setup Firebase Hosting
David demonstrates logging into and setting up the Firebase CLI to deploy web applications. A student's question regarding the difference between the doc and setDoc function is also covered in this segment.Dev Config Best Practices
David discusses what went against best practices in the previous Firebase demo and briefly demonstrates implementing best practices for security, code structure, production services, deployment, and data models. A student's question regarding if Firebase sets up a WebSocket when talking to the database is also covered in this segment.Setup Local Emulator Environment
David walks through connecting to the Auth and Firestore emulators, the contents of the firebase.json file, and enabling the Emulator UI. Student questions regarding how often the offline data store updates and caches data and if users and data can be populated in a development environment are also covered in this segment.
Firestore
Firestore & NoSQL Overview
David provides an overview of SQL databases, translates those concepts onto NoSQL databases, and provides pros and cons for both approaches. Firestore is a NoSQL document database with real-time and offline capabilities.Retrieving & Writing Data
David demonstrates retrieving data from Firestore by attaching a collection or document reference to the onSnapshot method. Using mutation functions such as setDoc, updateDoc, and deleteDoc to write data, generating path Ids, and server timestamps are also covered in this segment.Synchronization & Offline Caching
David discusses the difficulty of incrementing data on a real-time system, avoiding update errors by utilizing generated IDs, and an overview of the offline cache. Student questions regarding if there is a limit to the number of listeners on paths and how to indicate a disconnection from Firestore are also covered in this segment.Firestore Realtime Stream Exercise
Students are instructed to create realtime streams and map over the data.Firestore Realtime Stream Solution
David walks through the solution to the Firestore realtime stream exercise.
Querying
Querying Firestore
David briefly discusses simple and composite queries and walks through query operators, including equality, in, greater than, less than, and not-in. Simple queries involve querying based on one field, while composite queries involve querying based on more than one field.Simple Queries
David live codes examples of simple queries, including limited queries, queries for specific categories, less than queries, and queries for data within a set date range.Composite Queries & Indexes
David discusses creating custom sorted composite indexes for quick database querying. Student questions regarding if there is support for or queries, if queries can be ordered by date, and if there is a way to get queries back in random order are also covered in this segment.Composite Queries Exercise
Students are instructed to write a query for all expenses not categorized as fun, clothes, gifts, home, or personal, and a query for all expenses categorized as 'food' and occurred in January 2021 but not on 12/26/2021.Composite Queries Solution
David walks through the solution to the composite queries exercise.Map & Querying Arrays
David walks through querying through arrays with array operators such as array-contains and array-contains-any. A more complicated example of querying a date range with set excluded dates is also demonstrated in this segment.Range Queries & Cursoring Pagination
David demonstrates dividing large query results into smaller discrete pages using startAt and endAt to create references to data ranges.Denormalization & Document Structure
David discusses the difference between joins in SQL and NoSQL databases and the hierarchy of the document structure. How to update repeated data located in multiple collections and query across all subcollections is also covered in this segment.Collection Group Queries Exercise
David demonstrates the flexibility of NoSQL databases by walking through a few examples of collection group queries.Atomic Operations & Transaction
David discusses handling when an operation fails by making the process atomic with batched writes and transactions. Transactions run multiple operations in an atomic process including the access to reading data.
Authorization & Security
Enabling Firebase Authentication
David provides an overview of Firebase Auth, a serverless authentication provider with integration into Firebase security rules. A demo walkthrough of authenticating users, linking accounts, and admin permissions is also provided in this segment.Auth Q&A
David answers student questions regarding what anonymous login looks like, if there are any specifications to follow to create a custom auth provider, and how to decide which kind of auth to use.Security Rules
David discusses Security Rules as being used to determine access to Firebase resources on every request and live codes some Security Rules. Security Rules are centralized, written in a custom language, and must match at the document level.Authentication Security Rules
David walks through examples demonstrating testing and writing Security Rules to determine authenticated and unauthenticated users.Structural Security Rules
David live codes examples of structural Security Rules, which determine that the data sent to the server is the data the server expects. A demonstration of the Firestore request monitor is also provided in this segment.Role Based Access Control
David walks through examples of role-based access control Security Rules to determine a user's role and what that role has access to.Cloud Functions
David discusses functions that allow writing server code in response to events within Firebase without needing a server known as Cloud Functions. Functions are considered a trusted environment, allowing the Admin SDK to be used.CDN Cache & HTTP Requests
David walks through examples demonstrating using Cloud functions to set a CDN cache for an hour and make an HTTP request. This segment also covers configuring the firebase.json file to connect to Firebase hosting.Document Triggers
David live codes an example of a Cloud Function triggered by a document event. Users changing their data will trigger the Cloud Function to update it across all expenses.Admin SDK
David walks through an advanced use case for a Cloud Function to write a request to create a subcollection, look up a user by email with the Admin SDK, and add them as collaborators.Authentication Triggers
David walks through a continuation of the Admin SDK example by checking if a new user has any pre-existing collaborator requests and, if so, adding them as collaborators. A brief discussion regarding the auth triggers onCreate and onDelete and the v2 blocking functions beforeCreate and beforeSignIn.