Reputation: 1558
I have the following code snippet in my middleware/auth.js
export default function ({ store, router }) {
if (!store.state.admin.isAdmin) {
router.push({ path: '/auth/login' })
}
}
I want to redirect any unauthenticated users to login page. With the above code I'm getting error of:
Cannot read property 'push' of undefined
How do I access router properties in middleware so that I can redirect users ?
Upvotes: 0
Views: 719
Reputation: 876
This is my middleware/auth.js
:
export default function ({ app, redirect }) {
if (process.client) {
if (!app.$auth.loggedIn) {
redirect('/login');
}
}
}
Upvotes: 1