title: Vuejs Authentication JWT VUEX
body: <p>Hi i do vue authentication with jwt and vuex, and works well but i need to load token and user when i refresh page. i find online this code <code>store.dispatch('auth/attemptAuthtoken', localStorage.getItem('authToken'))</code>and works good but works only in main.js . I need to put it in index.js (main file of store) but if i use it i have problem with store/dispatch etc.
  <br>
  I try to import store but i've problem too.
  <br>
  <a href="https://i.stack.imgur.com/sD9zB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sD9zB.png" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/PlXvC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PlXvC.png" alt="enter image description here" /></a>
  <br>
  Someone can help me to fix it? (I started very recently to use vue / vuex)
  <br>
  <strong>main.js</strong></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>import { createApp } from 'vue'
  import App from './App.vue'
  import router from './router'
  import axios from 'axios'
  import store from './store'
  
  store.dispatch('auth/attemptAuthtoken', localStorage.getItem('authToken'))
  store.dispatch('auth/attemptUser', JSON.parse (localStorage.getItem('user')))
  
  axios.defaults.baseURL = 'https://**********/'
  
  createApp(App).use(store).use(router).mount('#app')</code></pre>
  </div>
  </div>
  </p>
  <p><strong>index.js</strong></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>import { createStore } from 'vuex'
  import auth from './auth.js'
  
  
  
  
  export default createStore({
    state: {
    },
    mutations: {
    },
    actions: {
    },
    modules: {
      auth
    }
  })</code></pre>
  </div>
  </div>
  </p>