How do you add route guards to this app? I tried adding the following in the index.js:
router.beforeEach((to, from, next) => {
const token = localStorage.usertoken
const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
if (requiresAuth && !token) next('login')
else if (!requiresAuth && token) next('profile')
else next()
})
export default router
... in order to prevent the user from being logged out after refreshing the page, but to no avail. Any recommendations on how to add route guards?
How do you add route guards to this app? I tried adding the following in the index.js:
... in order to prevent the user from being logged out after refreshing the page, but to no avail. Any recommendations on how to add route guards?