2026-01-17 21:17:43 +00:00
|
|
|
import { createRouter, createWebHistory } from 'vue-router'
|
2026-01-18 11:32:47 +00:00
|
|
|
import { useUserStore } from '../stores/userStore'
|
2026-01-17 21:17:43 +00:00
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
2026-01-18 11:32:47 +00:00
|
|
|
routes: [
|
|
|
|
|
{
|
|
|
|
|
path: '/',
|
|
|
|
|
name: 'home',
|
|
|
|
|
component: () => import('../views/HomeView.vue'),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/about',
|
|
|
|
|
name: 'about',
|
|
|
|
|
component: () => import('../views/AboutView.vue'),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/login',
|
|
|
|
|
name: 'login',
|
|
|
|
|
component: () => import('../views/LoginView.vue'),
|
|
|
|
|
meta: { guestOnly: true },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/register',
|
|
|
|
|
name: 'register',
|
|
|
|
|
component: () => import('../views/RegisterView.vue'),
|
|
|
|
|
meta: { guestOnly: true },
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
|
const userStore = useUserStore()
|
|
|
|
|
const isAuthenticated = userStore.isAuthenticated
|
|
|
|
|
// const is_manager = userStore.user?.is_manager || false
|
|
|
|
|
|
|
|
|
|
if (to.meta?.guestOnly && isAuthenticated) {
|
|
|
|
|
return next({ path: '/' })
|
|
|
|
|
}
|
|
|
|
|
if (to.meta?.requiresAuth && !isAuthenticated) {
|
|
|
|
|
return next({ path: '/login', query: { redirect: to.fullPath } })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return next()
|
2026-01-17 21:17:43 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default router
|