aboutsummaryrefslogtreecommitdiff
path: root/client/src/router/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/router/index.js')
-rw-r--r--client/src/router/index.js27
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;