2026-05-18 16:02:43 +03:30
|
|
|
import { createRouter, createWebHistory } from 'vue-router';
|
|
|
|
|
import { useAuthStore } from '@/stores/auth';
|
|
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
history: createWebHistory(),
|
2026-05-18 21:30:37 +03:30
|
|
|
routes: [
|
|
|
|
|
{ path: '/', redirect: '/login' },
|
|
|
|
|
{
|
|
|
|
|
path: '/login',
|
|
|
|
|
name: 'login',
|
|
|
|
|
component: () => import('@/views/auth/LoginView.vue'),
|
|
|
|
|
meta: { guest: true },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/verify',
|
|
|
|
|
name: 'verify',
|
|
|
|
|
component: () => import('@/views/auth/VerifyOtpView.vue'),
|
|
|
|
|
meta: { guest: true },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/app',
|
|
|
|
|
name: 'app-home',
|
|
|
|
|
component: () => import('@/views/app/AppHomeView.vue'),
|
|
|
|
|
meta: { requiresAuth: true },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/app/bookings',
|
|
|
|
|
name: 'app-bookings',
|
|
|
|
|
component: () => import('@/views/app/AppBookingsView.vue'),
|
|
|
|
|
meta: { requiresAuth: true },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/app/profile',
|
|
|
|
|
name: 'app-profile',
|
|
|
|
|
component: () => import('@/views/app/AppProfileView.vue'),
|
|
|
|
|
meta: { requiresAuth: true },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/app/owner',
|
|
|
|
|
name: 'app-owner',
|
|
|
|
|
component: () => import('@/views/app/AppOwnerView.vue'),
|
|
|
|
|
meta: { requiresAuth: true, requiresBusinessOwner: true },
|
|
|
|
|
},
|
|
|
|
|
{ path: '/home', redirect: '/app' },
|
|
|
|
|
],
|
2026-05-18 16:02:43 +03:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.beforeEach(async (to) => {
|
|
|
|
|
const auth = useAuthStore();
|
|
|
|
|
|
|
|
|
|
if (auth.token && !auth.user) {
|
|
|
|
|
await auth.loadUser();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (to.meta.requiresAuth && !auth.isLoggedIn) {
|
2026-05-18 21:30:37 +03:30
|
|
|
return { name: 'login' };
|
2026-05-18 20:18:28 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (to.meta.requiresBusinessOwner && !auth.isBusinessOwner && !auth.isAdmin) {
|
|
|
|
|
return { name: 'app-home' };
|
2026-05-18 16:02:43 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (to.meta.guest && auth.isLoggedIn) {
|
2026-05-18 20:18:28 +03:30
|
|
|
return { name: 'app-home' };
|
|
|
|
|
}
|
2026-05-18 16:02:43 +03:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default router;
|