title: how to keep user authenticated after refreshing the page in nuxtjs?
body: <p>I'm using laravel passport for API's and nuxt.js for frontend after a successful login if I refresh the page the user is not authenticated anymore and <code>loggedIn</code> returns false, its my first nuxt.js project so I have no idea how to deal with that, any advise is appreciated</p>
  <p><code>login.vue</code></p>
  <pre class="lang-html prettyprint-override"><code>&lt;script&gt;
  import { mapActions } from 'vuex'
  
  export default {
    data() {
      return {
        email: &quot;&quot;,
        password: &quot;&quot;
      }
    },
    methods:{
      async login(){
        const succesfulLogin = await this.$auth.loginWith('local', {
          data: {
            email: this.email,
            password: this.password
          },
        })
        this.$store.commit(&quot;saveUser&quot;,succesfulLogin.data)
        this.$store.commit(&quot;saveToken&quot;, succesfulLogin.data.token)
  
        if (succesfulLogin) {
          await this.$auth.setUser({
            email: this.email,
            password: this.password,
          })
          this.$router.push('/profile')
        }
      }
    }
  }
  &lt;/script&gt;
  </code></pre>
  <p><code>store/index.js</code></p>
  <pre class="lang-js prettyprint-override"><code>export const state = () =&gt; ({
    user:{},
    token: &quot;&quot;
  })
  
  export const mutations = {
    saveUser(state, payload) {
      state.user=payload;
    },
    saveToken(state, token) {
      state.token= token
    }
   
  }
  export const actions = {
       saveUserAction({commit}, UserObject){
           commit('saveUser');
       },
       logoutUser({commit}){
          commit('logout_user')
       }
  }
  export const getters = {
    getUser: (state) =&gt; {
      return state.user
    },
    isAuthenticated(state) {
      return state.auth.loggedIn
    },
  
    loggedInUser(state) {
      return state.user.user
    }
  }
  </code></pre>
  <p><strong>after a successful login</strong>
  <a href="https://i.stack.imgur.com/FTbPu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FTbPu.png" alt="enter image description here" /></a></p>
  <p><strong>after refreshing the page</strong>
  <a href="https://i.stack.imgur.com/CrPql.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CrPql.png" alt="enter image description here" /></a></p>