I have below beforeEach code in my vue js. I need to only check for loggedIn and not authRequired. If I remove the authRequired from the if condition, this function looks. Is there any other way I can just check localstorage value and not check authRequired.
router.beforeEach((to, from, next) => {
const publicPages = ['/login', '/register'];
const authRequired = !publicPages.includes(to.path);
const loggedIn = localStorage.getItem('user');
if (authRequired && !loggedIn) {
return next('/login');
}
next();
})
I have tried before code. Which gets stuck in continuous loop.
router.beforeEach((to, from, next) => {
const publicPages = ['/login', '/register'];
const loggedIn = localStorage.getItem('user');
if (!loggedIn) {
return next('/login');
}
next();
})