Firebase for the Web

36
Firebase For the Web Jana Moudrá @Janamou +JanaMoudra

Transcript of Firebase for the Web

Page 1: Firebase for the Web

Firebase

For the Web

Jana Moudrá @Janamou +JanaMoudra

Page 2: Firebase for the Web

Co-Founder at

Organizer at GDG Prague

Google Developer Expert for

About me

Jana Moudrá @Janamou +JanaMoudra

Page 3: Firebase for the Web

#firebasehackprague

FIREBASE?

Page 4: Firebase for the Web

#firebasehackprague

Page 5: Firebase for the Web

#firebasehackprague

Page 6: Firebase for the Web

#firebasehackprague

Page 7: Firebase for the Web

#firebasehackprague

LET’S START

Page 8: Firebase for the Web

1. Login to Firebase console

2. Create a new project

3. Copy the code to your project

4. Use Firebase

#firebasehackprague

Firebase How To

Page 9: Firebase for the Web

$ npm install -g firebase-tools

$ firebase login

$ firebase serve

firebase.google.com/docs/cli/

Firebase Tools

Page 10: Firebase for the Web

#firebasehackprague

Firebase For the Web

Page 11: Firebase for the Web

You may include every component independently

#firebasehackprague

Firebase For the Web

Page 12: Firebase for the Web

<script src="firebase.js"></script>

or

<script src="firebase-app.js"></script><script src="firebase-auth.js"></script><script src="firebase-database.js"></script><script src="firebase-storage.js"></script>

#firebasehackprague

Firebase For the Web

Page 13: Firebase for the Web

var firebase = require('firebase/app');

require('firebase/auth');

require('firebase/database');

require('firebase/storage);

npmjs.com/package/firebase

Firebase For the Web

Page 14: Firebase for the Web

E-mail/PasswordProviders

Google, Facebook, Twitter, Github

AnonymousCustom auth system integrationNeeds to be enabled in Firebase console

#firebasehackprague

Auth

Page 15: Firebase for the Web

firebase.auth().onAuthStateChanged(function(user) {

if (user) {

// Get data from user

} else {

// User is signed out

}

});

#firebasehackprague

Auth

Page 16: Firebase for the Web

// User can be null

var user = firebase.auth().currentUser;

#firebasehackprague

Auth

Page 17: Firebase for the Web

// Create a new account

firebase.auth()

.createUserWithEmailAndPassword(email, password);

// Login

firebase.auth()

.signInWithEmailAndPassword(email, password);

#firebasehackprague

Auth

Page 18: Firebase for the Web

// Can be Google, Facebook, Twitter or Github

var provider =

new firebase.auth.GoogleAuthProvider();

firebase.auth().signInWithPopup(provider);

firebase.google.com/docs/auth/web/manage-users

Auth

Page 19: Firebase for the Web

Cloud hosted storageData is stored as JSONRealtime synchronization

Automatic updates

Offline support

#firebasehackprague

Database

Page 20: Firebase for the Web

Asynchronous listening to events:value

child_added

child_changed

child_removed

child_moved

#firebasehackprague

Database - Retrieve

Page 21: Firebase for the Web

firebase.database().ref('users')

.on('value', function(snapshot) {

doSomethingWithData(snapshot.val());

});

#firebasehackprague

Database - Retrieve

Page 22: Firebase for the Web

firebase.database().ref('users')

.once('value', function(snapshot) {

doSomethingWithData(snapshot.val());

});

#firebasehackprague

Database - Retrieve

Page 23: Firebase for the Web

// Orders by child

firebase.database().ref('users')

.orderByChild('age');

// Limits to first 5

firebase.database().ref('users')

.limitToFirst(5);

#firebasehackprague

Database - Sort, Filter

Page 24: Firebase for the Web

#firebasehackprague

Database - Save

Methods:set()

push()

update()

transaction()

Page 25: Firebase for the Web

firebase.database().ref('messages')

.push({text: 'Ahoj'});

firebase.google.com/docs/database/web/start

Database - Save

Page 26: Firebase for the Web

firebase.google.com/docs/database/security/

Rules

Read and write access to db/storageHow data are structuredWhat indexes existFrom Firebase console

Page 27: Firebase for the Web

firebase.google.com/docs/storage/web/start

Storage

Backed by Google Cloud StorageFiles stored in Firebase storage bucket

Page 28: Firebase for the Web

For Chrome and Chrome apps/extensions

firebase.google.com/docs/cloud-messaging/chrome/client

Cloud Messaging

Page 29: Firebase for the Web

#firebasehackprague

Hosting

Static hosting for web appsfirebaseapp.com subdomainFirebase CLI needed

$ firebase init

$ firebase deploy

Page 30: Firebase for the Web

#firebasehackprague

MORE INFO?

Page 31: Firebase for the Web

firebase.google.com/docs/reference/

Page 32: Firebase for the Web

codelabs.developers.google.com/codelabs/firebase-web/index.html

Page 33: Firebase for the Web

firebase.google.com/docs/samples/

Page 34: Firebase for the Web

firebase.google.com/docs/libraries/

Page 35: Firebase for the Web

#firebasehackprague

HAPPY CODING!

Page 36: Firebase for the Web

Firebase

For the Web

Jana Moudrá @Janamou +JanaMoudra