Home

Issue: 2492

Middleware is not running when page refresh (F5) or direct access

[issue link]

The middleware works perfectly whenever the page redirect from one to another.
But when I tried to refresh the page or direct access to the page, the middleware is not running.

I run this middleware in nuxt.config.js

This is how I code my middleware,

nuxt.config.js

module.exports = {
  ...
  router: {
    middleware: ['check-auth', 'axios-header']
  }
}
axios-header.js

export default function ({ isServer, req, store }) {
    console.log('axios-header')
    if (isServer && !req) return
    const loggedUser = isServer ? getUserFromCookie(req) : getUserFromLocalStorage()
    if (loggedUser) {
        Axios.defaults.headers.common['authorization'] = `Bearer ${loggedUser}}`
    }
}
This question is available on Nuxt.js community (#c2163)