How to send some parameter to middleware?
For example, I have two pages: all_pages
and all_users
.
They initializaded with middleware. In the middleware, you need to check if the user object has permission. The problem is that for different pages you need to check different permissions. And you will have to create many similar types of middleware. It would be wonderful to have the ability to transfer to the middleware the resolution that should be checked:
// pages/all_pages.veu
export default {
name: 'all_pages',
middleware: ['check_access?permission=edit_pages'],
}
// pages/all_users.veu
export default {
name: 'all_users',
middleware: ['check_access?permission=edit_users'],
}
// middleware/check_access.js
export default function ({ store, error, params }) {
if (!store.state.currentUser.permissions.find(p => p === params.permission) {
return error(/* ... */)
}
}
<!--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/c614">#c614</a>)</em></sub></div>