From 72188822acfc3d8ee2f63ae559549e24c3363718 Mon Sep 17 00:00:00 2001 From: VIktorGrev <viktog2210@gmail.com> Date: Fri, 19 Apr 2024 11:39:11 +0200 Subject: [PATCH] feat: Adding iAuth in routing --- .../UserProfile/UserProfileLayout.vue | 2 -- src/router/index.ts | 32 ++++++++----------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/components/UserProfile/UserProfileLayout.vue b/src/components/UserProfile/UserProfileLayout.vue index 6734d71..e361157 100644 --- a/src/components/UserProfile/UserProfileLayout.vue +++ b/src/components/UserProfile/UserProfileLayout.vue @@ -18,7 +18,6 @@ function toRoadmap(){ </script> <template> - <Menu></Menu> <div class="container text-center"> <div class="row"> <div class="col"> @@ -120,7 +119,6 @@ function toRoadmap(){ </div> </div> </div> - <Footer></Footer> </template> <style scoped> diff --git a/src/router/index.ts b/src/router/index.ts index 2fa8ce7..838c9fa 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -17,10 +17,9 @@ const routes = [ path: '', name: 'home', component: () => import('../views/HomeView.vue'), - meta: { requiresAuth: true }, }, { - path: '/news', + path: 'news', name: 'news', component: () => import('@/views/NewsView.vue'), }, @@ -49,11 +48,16 @@ const routes = [ name: 'shop', component: () => import('@/views/ShopView.vue'), }, + { + path: '/profile', + name: 'profile', + component: UserProfileView + }, { path: 'admin', name: 'admin', component: () => import('@/views/TestView.vue'), - meta: { requiresAdmin: true } + meta: { requiresAdmin: true }, }, { path: 'unauthorized', @@ -72,11 +76,6 @@ const routes = [ name: 'login', component: LoginView, }, - { - path: '/profile', - name: 'profile', - component: UserProfileView - }, { path: '/sign-up', name: 'sign up', @@ -135,18 +134,13 @@ router.beforeEach((to, from, next) => { const userRole = user.role; const isAuthenticated = user.isLoggedIn; - /*if (requiresAuth && !isAuthenticated) { - next({ name: 'login' }); + if (requiresAuth && !isAuthenticated) { + next({ name: 'login', query: { redirect: to.fullPath } }); + } else if (requiresAdmin && userRole !== 'admin') { + next({ name: 'home' }); } else { - if (requiresAdmin && userRole !== 'admin') { - next({ name: 'unauthorized' }); - } else { - next(); - } - }*/ - - next(); - + next(); + } }); export default router; \ No newline at end of file -- GitLab