Skip to content

Instantly share code, notes, and snippets.

@menuka94
Last active January 22, 2017 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save menuka94/432d3f2b26de466f0d0f598f50033055 to your computer and use it in GitHub Desktop.
Save menuka94/432d3f2b26de466f0d0f598f50033055 to your computer and use it in GitHub Desktop.
Firebase Web
const auth = firebase.auth();
auth.singInWithEmailAndPassword(email, pass);
// create new user
auth.createUserWithEmailAndPassword(email, pass);
auth.onAuthStateChanged(firebaseUser => {});
(function () {
// Initialize Firebase
const config = {
apiKey: "",
authDomain: "",
databaseURL: "",
storageBucket: "",
messagingSenderId: ""
};
firebase.initializeApp(config);
var bigOne = document.getElementById('bigOne'); // <h1 id="bigOne"></h1>
var dbRef = firebase.database().ref().child('text');
dbRef.on('value', snap => bigOne.innerText = snap.val());
// get the element
const preObject = document.getElementById('object'); // <pre id="object"></pre>
const ulList = document.getElementById('list'); // <ul id="list"></ul>
// create references
const dbRefObject = firebase.database().ref().child('object');
const dbRefList = dbRefObject.child('hobbies');
// Sync object changes
dbRefObject.on('value', snap => {
preObject.innerText = JSON.stringify(snap.val(), null, 3);
});
// Sync list changes
dbRefList.on('child_added', snap => {
const li = document.createElement('li');
li.innerText = snap.val();
li.id = snap.key;
ulList.appendChild(li);
});
dbRefList.on('child_changed', snap => {
const liChanged = document.getElementById(snap.key);
liChanged.innerText = snap.val();
});
dbRefList.on('child_removed', snap => {
const liToRemove = document.getElementById(snap.key);
liToRemove.remove();
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment