Collection of Firebase snippets for my future use
-
posts
title
content
owner
createdAt
modifiedAt
isPublished
-
users
Get started
- Go to Firebase console
- Add project
- Create database from
Firestore Database
(Cloud Firestore) menu on the left
- I'm not using
Realtime Database
here
- I can still listen for realtime updates with
Firestore Database
Prep/config
CRUD
Create - setDoc
If your field needs to be unique, set the value as document ID
Read - getDoc (single document)
Read - getDocs (not realtime)
Read - onSnapshot (realtime updates)
Update - setDoc
Delete - deleteDoc
Auth
Signup
Login
Logout
Password reset
Error handling
Setting an observer on the Auth object - onAuthStateChanged