From 4b006aaa012d7b1477e302e66fa7389f8dcaf452 Mon Sep 17 00:00:00 2001 From: aserrador Date: Mon, 22 Jun 2026 12:50:14 -0500 Subject: [PATCH] #44 feat: restringir acceso a compras para usuarios con rol publico --- src/components/NavBar.vue | 10 ++++++++-- src/router/index.js | 4 ++++ src/stores/auth.js | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) 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: {