router.beforeEach((to, _from, next) => { if (to.matched.some(record => record.meta.requiresAuth)) { if (store.getters['auth/isLoggedIn']()) { next(); } else { next('/login'); } } else { next(); } });
router.beforeEach((to, from, next) => { if (to.matched.some(r => r.meta.requireAuth)) { if (store.state.token && store.state.auth) { next() } else { next({ path: '/login', query: { redirect: to.fullPath } }) } } else { next() } })
routes.beforeEach((to, from, next) => { let token = Cookies('username'); if (!to.name) { next({ name: 'list' }); } else if (to.name == 'login') { if (!token || !store.state.auth.username) { next(); } else { next({ name: 'list' }); } } else if (to.params.status == 2 || (to.matched.some(record => record.meta.requiresAuth) && (!token || token === null))) { next({ path: '/login' }); } else { next(); } });
router.beforeEach((to, from, next) => { if (store.getters.isAuthenticated) { if (to.path === '/auth/logout') { store.dispatch('logout') } else if (to.matched.some(record => record.meta.skipIfAuthorized)) { next({ path: '/home', }) } else { next() } } else if (to.matched.some(record => record.meta.isOpen)) { next() } else { next({ path: '/auth/login', query: { redirect: to.fullPath, }, }) } })
router.beforeEach((to, from, next) => { if(to.matched.some(record => record.meta.authenticated)) { if (isAuthenticated() === false) { next({ name: 'Login' }) } else { next() } } else if(to.matched.some(record => record.meta.guest)) { if(isAuthenticated() === false){ next() } else { next({ name: 'Profile'}) } } else { next() } })
router.beforeEach(async (to, from, next) => { if (to.matched.some(record => record.meta.requiresAuth)) { await Store.dispatch("restoreUser"); const currentUser = Store.getters.currentUser; if (!currentUser) { return next({ path: "/", params: { nextUrl: to.fullPath } }); } else if (!_.includes(currentUser.groups, 'admins')) { /** * Note: a non admin can technically login to the admin panel, * however none of the api calls that follows would work, leaving them an empty blank page. * We gracefully redirect them to the login page with a message. */ Store.dispatch('logout'); return next({ path: "/", params: { nextUrl: to.fullPath, error: 'Access forbidden' } }); } } next(); });
router.beforeEach((to, _from, next) => { if (to.matched.some(record => record.meta.requiresAuth)) { if (store.getters['auth/isLoggedIn']()) { next(); } else { next('/login'); } } else { next(); } });