From 015d67cf738e4ad6d397824dc09a44d85d643b75 Mon Sep 17 00:00:00 2001 From: Mateja Date: Thu, 29 Jul 2021 02:46:33 +0200 Subject: Fully implement client-side login system... --- client/src/router/index.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'client/src/router') diff --git a/client/src/router/index.js b/client/src/router/index.js index eee610c..ee78676 100644 --- a/client/src/router/index.js +++ b/client/src/router/index.js @@ -5,6 +5,8 @@ import Checkout from '@/views/Checkout.vue'; import Login from '@/views/Login.vue'; import Register from '@/views/Register.vue'; +import store from '@/store/index'; + const routes = [ { path: '/', @@ -24,12 +26,18 @@ const routes = [ { path: '/login', name: 'Login', - component: Login + component: Login, + meta: { + guest: true + } }, { path: '/register', name: 'Register', - component: Register + component: Register, + meta: { + guest: true + } } ]; @@ -38,4 +46,19 @@ const router = createRouter({ routes }); +router.beforeEach((to, from) => { + if (to.matched.some(record => record.meta.guest) && store.getters.isLoggedIn) + return false; + + if (to.matched.some(record => record.meta.admin) && !store.getters.isAdmin) + return false; + + if (to.matched.some(record => record.meta.auth) && !store.getters.isLoggedIn) { + from.params.nextUrl = to.fullPath; + return '/login'; + } + + return true; +}); + export default router; -- cgit v1.2.3