title: Nuxt - can i run client side code from a middleware in Universal mode?
body: <p>I'm working on a universal Nuxt app that uses the standard Django session authentication.
  I need to restrict some pages in my project to logged in users only, so i decided to use a middleware.</p>
  <p>The problem with the middleware is that it will run from server side, so it will always return <code>False</code> to the user even when the user is logged in, since it doesn't send any cookie in the request. This happens only when i refresh page or when i navigate directly to it, not when i navigate from another page to a restricted page, that's because in that case the middleware is executed client side and not server side.</p>
  <p>Is there any way i can &quot;force&quot; the following code to run client side instead of server side from the middleware? Or do i have to look for another solution?</p>
  <pre><code>export default async function (context) {
    axios.defaults.withCredentials = true;
    return axios({
      method: 'get',
      url: 'http://127.0.0.1:8000/checkAuth',
      withCredentials: true,
    }).then(function (response) {
      //Check if user is authenticated - response is always False
    }).catch(function (error) {
      //Handle error
    });
  }
  </code></pre>
  <p>I tried to do the same with <code>nuxtServerInit</code> but the outcome is the same. If i run that code in the <code>beforeCreate</code> block from the page it will first load the page and then execute the request, which works but it's quite ugly since the user will see the page for a second before being redirected. Any advice is appreciated</p>