Files
InvoiceShelf/resources/scripts/router/index.js
Darko Gjorgjijoski f623cd0179 Upgrade vue-router from v4 to v5 (#598)
- Migrate beforeEach navigation guard from next() callback to return-based
  API, preparing for vue-router v6 where next() is removed
2026-04-02 16:47:16 +02:00

38 lines
1011 B
JavaScript
Vendored

import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '@/scripts/admin/stores/user'
import { useGlobalStore } from '@/scripts/admin/stores/global'
//admin routes
import AdminRoutes from '@/scripts/admin/admin-router'
// Customers routes
import CustomerRoutes from '@/scripts/customer/customer-router'
//Payment Routes
let routes = []
routes = routes.concat(AdminRoutes, CustomerRoutes)
const router = createRouter({
history: createWebHistory(),
linkActiveClass: 'active',
routes,
})
router.beforeEach((to) => {
const userStore = useUserStore()
const globalStore = useGlobalStore()
let ability = to.meta.ability
const { isAppLoaded } = globalStore
if (ability && isAppLoaded && to.meta.requiresAuth) {
if (!userStore.hasAbilities(ability)) {
return { name: 'account.settings' }
}
} else if (to.meta.isOwner && isAppLoaded) {
if (!userStore.currentUser.is_owner) {
return { name: 'dashboard' }
}
}
})
export default router