Files
webMontime/src/router/index.ts
T

88 lines
2.3 KiB
TypeScript
Raw Normal View History

2026-05-18 16:02:43 +03:30
import { createRouter, createWebHistory } from 'vue-router';
import { useAuthStore } from '@/stores/auth';
2026-06-12 20:16:14 +03:30
import { useProfileModalStore } from '@/stores/profile-modal';
import { loginRouteWithRedirect } from '@/utils/auth-redirect';
2026-05-18 16:02:43 +03:30
const router = createRouter({
history: createWebHistory(),
2026-05-18 21:30:37 +03:30
routes: [
2026-06-12 20:16:14 +03:30
{ path: '/', redirect: '/app' },
2026-05-18 21:30:37 +03:30
{
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'),
},
{
path: '/app/businesses/:id',
name: 'app-business-detail',
component: () => import('@/views/app/AppBusinessDetailView.vue'),
},
{
2026-05-18 21:30:37 +03:30
path: '/app/bookings',
name: 'app-bookings',
component: () => import('@/views/app/AppBookingsView.vue'),
meta: { requiresAuth: true },
},
{
path: '/app/profile',
name: 'app-profile',
meta: { requiresAuth: true },
2026-06-12 20:16:14 +03:30
redirect: () => {
useProfileModalStore().open();
return { name: 'app-home' };
},
2026-05-18 21:30:37 +03:30
},
{
path: '/app/register-business',
name: 'app-register-business',
component: () => import('@/views/app/AppRegisterBusinessView.vue'),
meta: { requiresAuth: true, requiresCustomer: true },
},
2026-05-18 21:30:37 +03:30
{
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();
2026-05-31 14:12:18 +03:30
if (auth.token && !auth.user) {
2026-05-18 16:02:43 +03:30
await auth.loadUser();
}
if (to.meta.requiresAuth && !auth.isLoggedIn) {
2026-06-12 20:16:14 +03:30
return loginRouteWithRedirect(to.fullPath);
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.requiresCustomer && !auth.isCustomer) {
return auth.isBusinessOwner ? { name: 'app-owner' } : { 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;