Reputation: 613
I created a folder middleware and a file called auth.js.
auth.js
export default function auth() {
console.log('auth!')
}
And in nuxt.config.js
I'm calling it in router object.
router: {
middleware: ['auth']
},
And every page that I enter I see the console.log I put in Auth.js. And what I'm trying to do is to avoid the middleware to run in Login page, but even when I set it to false, it runs.
Login.vue
<template>
<div class="div">LOGIN PAGE!!!</div>
</template>
<script>
export default {
auth: false
}
</script>
Upvotes: 1
Views: 266
Reputation: 46632
Here, you auth: false
is a confusion that you're making regarding nuxt-auth module.
Here, since you're not using that, you cannot bypass your middleware with auth: false
, it doesn't have any effect tbh.
If you want to have a conditional middleware in your component, you can use this approach.
Otherwise, you can write something similar in a /middleware/auth.js
file too.
You could even probably make a similar behavior of checking some auth
key on the instance yourself (homemade solution).
For an approach on how to do that, check this article with the point 18. Component Metadata
.
Upvotes: 1