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}}`
}
}
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c2163">#c2163</a>)</em></sub></div>