#44 feat: restringir acceso a compras para usuarios con rol publico
This commit is contained in:
@@ -54,7 +54,7 @@
|
|||||||
nav
|
nav
|
||||||
>
|
>
|
||||||
<v-list-item
|
<v-list-item
|
||||||
v-for="item in menuItems"
|
v-for="item in filteredMenuItems"
|
||||||
:key="item.title"
|
:key="item.title"
|
||||||
:title="item.title"
|
:title="item.title"
|
||||||
:prepend-icon="item.icon"
|
:prepend-icon="item.icon"
|
||||||
@@ -120,7 +120,13 @@
|
|||||||
computed: {
|
computed: {
|
||||||
isAdmin() {
|
isAdmin() {
|
||||||
return this.user?.role === 'administrator';
|
return this.user?.role === 'administrator';
|
||||||
|
},
|
||||||
|
filteredMenuItems() {
|
||||||
|
if (this.user?.role === 'publico') {
|
||||||
|
return this.menuItems.filter(item => item.route !== '/comprar');
|
||||||
}
|
}
|
||||||
|
return this.menuItems;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.checkAuth();
|
this.checkAuth();
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import { setupLayouts } from 'virtual:generated-layouts'
|
|||||||
import { routes } from 'vue-router/auto-routes'
|
import { routes } from 'vue-router/auto-routes'
|
||||||
import { useAuthStore } from '@/stores/auth'
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
|
||||||
|
const PUBLICO_RESTRICTED = ['/comprar']
|
||||||
|
|
||||||
const ADMIN_ROUTES = [
|
const ADMIN_ROUTES = [
|
||||||
'/sincronizar_clientes_tryton',
|
'/sincronizar_clientes_tryton',
|
||||||
'/sincronizar_ventas_tryton',
|
'/sincronizar_ventas_tryton',
|
||||||
@@ -40,6 +42,8 @@ router.beforeEach((to, from, next) => {
|
|||||||
next({ path: '/autenticarse', replace: true })
|
next({ path: '/autenticarse', replace: true })
|
||||||
} else if (requiresAdmin && !authStore.isAdmin && authStore.user) {
|
} else if (requiresAdmin && !authStore.isAdmin && authStore.user) {
|
||||||
next({ path: '/', replace: true })
|
next({ path: '/', replace: true })
|
||||||
|
} else if (authStore.user?.role === 'publico' && PUBLICO_RESTRICTED.includes(to.path)) {
|
||||||
|
next({ path: '/catalog', replace: true })
|
||||||
} else {
|
} else {
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export const useAuthStore = defineStore('auth', {
|
|||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
isAdmin: (state) => state.user?.role === 'administrator',
|
isAdmin: (state) => state.user?.role === 'administrator',
|
||||||
|
isPublico: (state) => state.user?.role === 'publico',
|
||||||
isAuthenticated: (state) => !!state.user
|
isAuthenticated: (state) => !!state.user
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
|||||||
Reference in New Issue
Block a user