diff --git a/src/components/NavBar.vue b/src/components/NavBar.vue index ad8c616..205c46b 100644 --- a/src/components/NavBar.vue +++ b/src/components/NavBar.vue @@ -54,7 +54,7 @@ nav > item.route !== '/comprar'); + } + return this.menuItems; + }, }, mounted() { this.checkAuth(); diff --git a/src/router/index.js b/src/router/index.js index a896bdd..0377c58 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -11,6 +11,8 @@ import { setupLayouts } from 'virtual:generated-layouts' import { routes } from 'vue-router/auto-routes' import { useAuthStore } from '@/stores/auth' +const PUBLICO_RESTRICTED = ['/comprar'] + const ADMIN_ROUTES = [ '/sincronizar_clientes_tryton', '/sincronizar_ventas_tryton', @@ -40,6 +42,8 @@ router.beforeEach((to, from, next) => { next({ path: '/autenticarse', replace: true }) } else if (requiresAdmin && !authStore.isAdmin && authStore.user) { next({ path: '/', replace: true }) + } else if (authStore.user?.role === 'publico' && PUBLICO_RESTRICTED.includes(to.path)) { + next({ path: '/catalog', replace: true }) } else { next() } diff --git a/src/stores/auth.js b/src/stores/auth.js index a9b373d..2ce3f5c 100644 --- a/src/stores/auth.js +++ b/src/stores/auth.js @@ -6,6 +6,7 @@ export const useAuthStore = defineStore('auth', { }), getters: { isAdmin: (state) => state.user?.role === 'administrator', + isPublico: (state) => state.user?.role === 'publico', isAuthenticated: (state) => !!state.user }, actions: {