Agregando proteccion a rutas #38

Merged
mono merged 3 commits from add-auth-protection-routes into main 2026-03-15 23:54:32 -05:00
Showing only changes of commit c1fccc4d53 - Show all commits

View File

@@ -9,6 +9,17 @@
import { createRouter, createWebHistory } from 'vue-router/auto'
import { setupLayouts } from 'virtual:generated-layouts'
import { routes } from 'vue-router/auto-routes'
import { useAuthStore } from '@/stores/auth'
const ADMIN_ROUTES = [
'/sincronizar_clientes_tryton',
'/sincronizar_ventas_tryton',
'/sincronizar_productos_tryton',
'/ventas_para_tryton',
'/cuadres_de_tarro',
'/compra_admin',
'/cuadrar_tarro',
]
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
@@ -18,9 +29,14 @@ const router = createRouter({
router.beforeEach((to, from, next) => {
const isAuthenticated = !!localStorage.getItem('access_token')
const requiresAuth = to.meta.requiresAuth === true
const requiresAdmin = to.meta.requiresAdmin === true || ADMIN_ROUTES.includes(to.path)
const authStore = useAuthStore()
if (requiresAuth && !isAuthenticated) {
next({ path: '/autenticarse', replace: true })
} else if (requiresAdmin && !authStore.isAdmin) {
next({ path: '/', replace: true })
} else {
next()
}