Skip to content

Instantly share code, notes, and snippets.

@hellerbenjamin
Created July 23, 2021 16:30
Show Gist options
  • Save hellerbenjamin/081c2282215d9e25213e3466df543e3a to your computer and use it in GitHub Desktop.
Save hellerbenjamin/081c2282215d9e25213e3466df543e3a to your computer and use it in GitHub Desktop.
Nuxt add middleware from module
const path = require('path')
export default function plugins(_moduleOptions) {
this.nuxt.hook('build:templates', ({ templateVars }) => {
templateVars.middleware.push({
name: 'authenticated',
src: path.resolve(__dirname, 'middleware/authenticated.js'),
fileName: path.join('authenticated.js'),
options: Object.assign({}, this.options.packageName)
})
templateVars.router.middleware.push('authenticated')
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment