Let’s talk about
Typical* Single Page Application architecture
*modern
Slide 4
Slide 4 text
DATA FLOW
⊗ REST API which queries database by some
parameters
⊗ Returns data in JSON format (via Observable)
⊗ Displays it on frontend
⊗ Polls every second or so to get latest data*
⊗ *or use Websockets...
Slide 5
Slide 5 text
SAVING DATA INPUTTED BY USER
⊗ Handle form input
⊗ Send data to REST API
⊗ Check authorization
⊗ Save in database
⊗ Get back to the list (make sure to display new
content if was created in the meantime)
Slide 6
Slide 6 text
THAT’S A LOT
OF BORING
WORK
Slide 7
Slide 7 text
⊗ Providing REST API (which has quite repetitive methods)
⊗ … or Websockets server to ensure better experience
⊗ Maintaining database
⊗ Managing users’ sessions and authorization
Slide 8
Slide 8 text
WHAT IF WE GET RID OF
BACKEND?
… and backend developers?
Slide 9
Slide 9 text
GOOGLE FIREBASE PLATFORM
⊗ Realtime database
⊗ Auth service
⊗ Hosting
⊗ Cloud functions
⊗ … and many more
Slide 10
Slide 10 text
FIRESTORE - realtime database
⊗ Cloud hosted
⊗ NoSQL database
⊗ Client libraries for Android, iOS, Javascript
(Angular, React etc.)
⊗ Oriented around documents and collections
(like MongoDB)
⊗ Realtime
FIRESTORE IS PUBLICLY
AVAILABLE
how’s that secure?
Slide 21
Slide 21 text
FIREBASE AUTH + DATABASE
⊗ Couple lines of code to setup authentication
⊚ Federated identity providers (FB, Google, Twitter, Github)
⊚ Email and password based protection
⊚ Custom auth system integration
⊗ Wide range of possibilities of protecting collections based
on auth state
⊗ FirebaseUI handles sign-in flow
HOW ABOUT LOGIC
RELATED TO DATA?
For example: send an email when new opinion is
created
Slide 25
Slide 25 text
SERVERLESS!
Here: Cloud Functions
Slide 26
Slide 26 text
CLOUD FUNCTIONS
⊗ JS/TS function being invoked on certain trigger
⊗ Trigger can be HTTP or related to Firestore document
(change, create, delete)
⊗ Ability to run any JS/TS code with any dependencies based
on event data
firebase deploy --only functions
Slide 27
Slide 27 text
No content
Slide 28
Slide 28 text
CLOUD FUNCTIONS - PREPARE
import * as functions from 'firebase-functions';
import * as nodemailer from 'nodemailer';
const mailTransport = nodemailer.createTransport({
service: 'gmail',
auth: { user: '***', pass: '*** }, // better: use ENV vars
});