window.onload = () => { // When page loads, check use logged in state firebase.auth().onAuthStateChanged(function(user) { if (user) { // if user is logged in, get user's notes from db // display notes on page const googleUserId = user.uid; getNotes(googleUserId); } else { // if user is not logged in, redirect to login page window.location = 'index.html'; } }) }; // Get the users notes from the db, display notes on page const getNotes = (userId) => { console.log(userId); const userRef = firebase.database().ref(`users/${userId}`); userRef.on('value', snapshot => { console.log(snapshot.val()); writeNotesToHtml(snapshot.val()); }) } const writeNotesToHtml = (data) => { const noteRenderArea = document.querySelector('#app'); for (let noteKey in data) { // create html stirng for one note let noteHtml = createHtmlForNote(data[noteKey]); noteRenderArea.innerHTML += noteHtml; } //put all html into page at once } // Returns a string t const createHtmlForNote = (note) => { // TODO: create the elemts and put in the note data return `${note.title}, ${note.text}`; };