title: Nuxt/Vue - how to run code before a page is rendered?
body: <p>I'm building a Nuxt app (SSR) that uses Django on the backend, for authenticating users i'm using the standard Django Session Auth.</p>
  <p>I'm completely stuck on the part where i need to redirect user to the login page when the user is rendered. So what i need to do is to send a request to my Django backend that will return whether the user is authenticated or not. Is there any way i can execute code before the HTML in my page is rendered?</p>
  <p><strong>What i tried:</strong></p>
  <p><strong>Middleware</strong>: I tried this with a middleware but for some reason Nuxt middlewares don't work with Axios. When i send the request from the Middleware, it won't send any Cookie along with the request so i will always be logged out (even when i'm logged in). This is a problem with Nuxt and not with the backend, because if i try the same request from a simple page it will work without any problem:</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>