title: Nuxt Firebase Authentication Middleware
body: <p>I'm using Nuxt(vue) as frontend and Firestore and Authentication as Backend. I got the authentication to work to a certain amount, but my problem is refreshing the browser resets the state so my Middleware returns a false  result.</p>
  
  <p>Here some code snippets:</p>
  
  <p>Middleware: </p>
  
  <pre><code>export default function ({store, redirect, route}) {
  
      const userIsLoggedIn = !!store.state.currentUser; 
  
      if(!userIsLoggedIn) {
          return redirect ('/')
      } 
  }
  </code></pre>
  
  <p>Plugin:</p>
  
  <pre><code>import { auth } from '@/services/firebaseInit.js'
  
  export default (context) =&gt; {
      const { store } = context
  
      return new Promise((resolve, reject) =&gt; {
          auth.onAuthStateChanged(user =&gt; {
              store.commit('setCurrentUser', user)
              resolve()
          })
      })
  }
  </code></pre>
  
  <p>Now this works in running App but when someone refreshes a page where you need auth it doesnt work and redirect to /, now i dont know how to solve that, would appreciate help and if you need more code then i provide it. </p>
  
  <p>EDIT 1:</p>
  
  <pre><code>   async nuxtServerInit ({ commit }, { req }) {
              let user = await firebase.auth().currentUser
  
              commit('setCurrentUser', user)
          }
  </code></pre>