title: How to wait for firebase.database().ref('users/' + userId).set() to finish before calling next function?
body: <p>I'm using the following asynchronous function to write data to my firebase instance:</p>
  
  <pre><code>function writeUserData(uid, fn, ln, userEmail) {
    firebase.database().ref('users/' + uid).set({
      firstName: fn,
      lastName: ln, 
      email: userEmail
    });
  };
  </code></pre>
  
  <p>Once writeUserData has finished, then I want to redirect the user to a different page:</p>
  
  <pre><code>window.location.href = "./mypage.html";
  </code></pre>
  
  <p>As far as I can understand, this can be done with <a href="https://firebase.googleblog.com/2016/01/keeping-our-promises-and-callbacks_76.html" rel="nofollow noreferrer">promises</a> but I could really use a good example to wrap my head around this.</p>