Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducing the art of Firebase

Introducing the art of Firebase

Avatar for Óscar Caballero

Óscar Caballero

December 30, 2015

More Decks by Óscar Caballero

Other Decks in Programming

Transcript

  1. (BaaS) back-end as a service GDG Cáceres Oscar Caballero Organizer

    of GDG Cáceres /oscarcpozas @oscar_pozas +OscarCaballeroPozas96
  2. The back-end expects ➔ Speed ➔ Security ➔ Easy authentication

    GDG Cáceres ➔ Offline mode ➔ Cross-platform ➔ Scalable
  3. Realtime back-end: If the data change, all listeners will be

    called. All data always is up to date. GDG Cáceres
  4. Database Advantages: • NoSQL data-store • Database is stored as

    JSON • Automatically scales with your app • Cross-platform • Offline mode GDG Cáceres
  5. The rules By default { "rules": { ".read": true, ".write":

    true, ".validate": "newData.isString() && newData.val().length < 100" } } Three basic rules .read → if and when data is allowed to be read by users. .write → if and when data is allowed to be written. .validate → Defines what a correctly formatted value. GDG Cáceres
  6. The rules II { "messages": { "message0": { "content": "Hello",

    "timestamp": 1405704370369 }, "message1": { "content": "Goodbye", "timestamp": 1405704395231 }, ... } } { "rules": { "messages": { "$message": { // only messages from the last ten minutes can be read ".read": "data.child('timestamp').val() > (now - 600000)", // new messages must have a string content and a number timestamp ".validate": "newData.hasChildren(['content', 'timestamp'])" } } } } GDG Cáceres
  7. Login users Firebase ref = new Firebase("https://my-example.firebaseio.com"); Firebase.AuthResultHandler authResultHandler =

    new Firebase.AuthResultHandler() { @Override public void onAuthenticated(AuthData authData) {} @Override public void onAuthenticationError(FirebaseError firebaseError) {} }; // Authenticate users with a custom Firebase token ref.authWithCustomToken("<token>", authResultHandler); // Alternatively, authenticate users anonymously ref.authAnonymously(authResultHandler); // Or with an email/password combination ref.authWithPassword("[email protected]", "correcthorsebatterystaple", authResultHandler); // Or via popular OAuth providers ("facebook", "github", "google", or "twitter") ref.authWithOAuthToken("<provider>", "<oauth-token>", authResultHandler); GDG Cáceres
  8. my-site.firebaseapp.com 1. cd /your-project-folder 2. firebase login 3. firebase init

    → Edit firebase.json 4. firebase deploy GDG Cáceres
  9. References, more info, another examples https://www.firebase.com/docs → Firebase apps examples

    • https://www.firebase.com/docs/web/examples.html • https://www.firebase.com/docs/ios/examples.html • https://www.firebase.com/docs/android/examples.html • https://goo.gl/fNq5IZ → Connect with your services • https://zapier.com GDG Cáceres