title: getting data from FireStore: works sometimes, doesn't other times
body: <p>I have the following firestore function to get user data:</p>
  <pre><code>export function getUser(uid) {
    return firestore.collection('users').doc(uid).get().then(user =&gt; {
      console.log({x:user.data(),uid});
      return user.data();
    })
  }
  </code></pre>
  <p>Inexplicably, sometimes this function will work absolutely fine, and the <code>console.log({x:user.data()})</code> will return the object I'm looking for. But often it will return <code>x: undefined</code> and will crash all other code. Is there something wrong with my function - why does it work sometimes and doesn't other times, how can I get it to work consistently?</p>
  <p>I notice this error occurs more often when I open my web-app already signed in. Doesn't seem to happen when I go incognito mode. Is there a way to check if the data returned is undefined, and if it is, to retry the code? Or a better way to write this function?</p>