diff options
author | Mateja <mail@matejamaric.com> | 2021-07-29 02:46:33 +0200 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2021-07-29 02:46:33 +0200 |
commit | 015d67cf738e4ad6d397824dc09a44d85d643b75 (patch) | |
tree | 122c50c85b5659332117b735790231b257b4724a /client/src/router | |
parent | 9f4a1c17d4f544784dc5e11ecf6d04c8b5d0582a (diff) | |
download | mevn-ecommerce-015d67cf738e4ad6d397824dc09a44d85d643b75.tar.gz mevn-ecommerce-015d67cf738e4ad6d397824dc09a44d85d643b75.zip |
Fully implement client-side login system...
Diffstat (limited to 'client/src/router')
-rw-r--r-- | client/src/router/index.js | 27 |
1 files changed, 25 insertions, 2 deletions
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; |