title: Token Authorization header with passport in vue.js
body: <p>Where can i put the Authorization header token in axios after dispatching login action with laravel passport authentication in a seprated vue.js project?I tried with setting it in main.js like this and doesnt work properly. After dispatching, In the QuestionIndex component, the axios call dont have the authorization header automatically. And by refreshing the page, it has the authorization header. I can fix this by putting the token header in QuestionIndex Component. But I dont think this is a proper way to do it. Please help me with this problem.
  In main.js</p>
  <pre><code>const token = localStorage.getItem('access_token');
  if (token) {
    axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
  }
  </code></pre>
  <p>In login.vue</p>
  <pre><code>login(){
               this.$store
                  .dispatch(&quot;login&quot;, this.form)
                  .then(() =&gt; {
                      this.$router.push({ name: &quot;QuestionIndex&quot; });
                  })
                  .catch(err =&gt; {
                      
                      console.log(err);
                  });
          }
  </code></pre>
  <p>In vuex store</p>
  <pre><code>  state: {
          token: localStorage.getItem('access_token') || null,
          user: {},
      },
      mutations: {
          setToken(state, data) {
              state.token = data.token;
              state.user = data.user;
          },
         
      },
      actions: {
         
          login({ commit }, credentials) {
              return axios.post(&quot;http://127.0.0.1:8000/api/login&quot;, credentials).then(( res ) =&gt; {
                  localStorage.setItem('access_token', res.data.data.token);
                  commit(&quot;setToken&quot;, res.data.data);
              });
          },
      },
      getters: {
          token: (state) =&gt; state.token,
      
      }
  </code></pre>