title: Access token cached when using nuxtServerInit
body: <p>I'm having an authorization (JWT) related caching issue when using Nuxt.</p>
  
  <p>This is the <code>nuxtServerInit</code> action, where I set the access token:</p>
  
  <pre class="lang-js prettyprint-override"><code>// store/index.js
  
  import cookie from 'cookie';
  
  export const state = () =&gt; ({
    authCookie: 'MyAuthCookie',
  });
  
  export const actions = {
    async nuxtServerInit({ dispatch, commit, state }, { req }) {
      // Check for access token
      const accessToken = req.headers.cookie &amp;&amp;
        cookie.parse(req.headers.cookie)[state.authCookie];
  
      // Set the access token, if there is one
      if (accessToken) {
        commit('auth/setAccessToken', accessToken);
      }
    },
  };
  </code></pre>
  
  <p>The <code>accessToken</code> state is later used to set the <code>Authorization</code> header for all future requests in this plugin:</p>
  
  <pre class="lang-js prettyprint-override"><code>// plugins/axios.js
  
  export default function ({ app, store }) {
    app.$axios.onRequest((config) =&gt; {
      // Set the `Authorization` header for future requests if we're logged in
      if (store.getters['auth/isLoggedIn']) {
        config.headers.common.Authorization = `Bearer ${store.state.auth.accessToken}`;
      }
    });
  };
  </code></pre>
  
  <p>Nuxt stores data shared between client and server in a global <code>window.__NUXT__</code> variable in an inlined <code>&lt;script&gt;</code> tag, and because I am aggressively caching the page in question (using Akamai), the access token will never be updated.</p>
  
  <p>Is there a better way of handling this, and to prevent the access token from being cached? Or in other words how do I prevent the <code>accessToken</code> state to be written to the global <code>__NUXT__</code> variable?</p>