Juan David Maldonado

Video Games

Languages

Paintball

Puzzles

@jdmaldonado06

Develop

Juan David Maldonado

Firebase

Initialize


<script src="https://www.gstatic.com/firebasejs/4.11.0/firebase.js"></script>
<script>
  // Initialize Firebase
  var config = {
    apiKey: "XXXXXXXXxxXXXxXXXXXXXxXXXxxxxxXXxx",
    authDomain: "firebase-jd-demo.firebaseapp.com",
    databaseURL: "https://firebase-jd-demo.firebaseio.com",
    projectId: "firebase-jd-demo",
    storageBucket: "firebase-jd-demo.appspot.com",
    messagingSenderId: "000000000000"
  };
  firebase.initializeApp(config);
</script>

JSON

JavaScript Object Notation

Width

Speed

Easy To Use

{
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

Example

Title Text

{
  "chats": {
    "one": {
      "title": "Historical Tech Pioneers",
      "lastMessage": "ghopper: Relay malfunction found. Cause: moth.",
      "timestamp": 1459361875666
    },
    "two": { ... },
    "three": { ... }
  },
  "members": {
    "one": {
      "ghopper": true,
      "alovelace": true,
      "eclarke": true
    },
    "two": { ... },
    "three": { ... }
  },
  "messages": {
    "one": {
      "m1": {
        "name": "eclarke",
        "message": "The relay seems to be malfunctioning.",
        "timestamp": 1459361875337
      },
      "m2": { ... },
      "m3": { ... }
    },
    "two": { ... },
    "three": { ... }
  }
}

Queries

var database = firebase.database();
function writeUserData(userId, name, email, imageUrl) {
  firebase.database().ref('users/' + userId).set({
    username: name,
    email: email,
    profile_picture : imageUrl
  });
}
var starCountRef1 = firebase.database().ref('users/' + userId);
starCountRef1.on('value', function(snapshot) {
  updateStarCount(postElement, snapshot.val());
});

var starCountRef2 = firebase.database().ref('users/' + userId);
starCountRef2.on('value',(snapshot) => {
  updateStarCount(postElement, snapshot.val());
});

Multiple accounts

firebase.auth().signInWithPopup(provider).then(function(result) {
  // This gives you a Google Access Token. You can use it to access the Google API.
  var token = result.credential.accessToken;
  // The signed-in user info.
  var user = result.user;
  // ...
}).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // The email of the user's account used.
  var email = error.email;
  // The firebase.auth.AuthCredential type that was used.
  var credential = error.credential;
  // ...
});
firebase.auth().createUserWithEmailAndPassword(email, password)
.catch((error) => {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...
});

Storage

  • Flexibility
  • Real Time
  • Not Conection
  • Security

Code

// Create a root reference
var storage = firebase.app().storage("gs://my-custom-bucket");

// Create a reference to 'images/mountains.jpg'
var mountainImagesRef = storageRef.child('images/mountains.jpg');

var file = ... 
// use the Blob or File API
//Can Use (Strings, Bytes Array)

var uploadTask = ref.put(file).then(function(snapshot) {
  console.log('Uploaded a blob or file!');
});


// Pause the upload
uploadTask.pause();

// Resume the upload
uploadTask.resume();

// Cancel the upload
uploadTask.cancel();

https://sob-admin.firebaseapp.com

sob-admin

https://

firebaseapp.com

{
    projectId: "sob-admin"
}

Deploy

NodeJS

npm install -g firebase-tools

firebase init

firebase deploy

Code Time

Thank you!

Firebase

By Juan David Maldonado

Firebase

  • 373