Описание изменений

This commit is contained in:
2025-03-06 21:31:29 +03:00
parent 3157ad0cd9
commit 765637f2d0
57 changed files with 6240 additions and 3695 deletions

View File

@@ -1,12 +1,7 @@
import { createRouter, createWebHistory } from 'vue-router';
import { useAuthStore } from '../stores/auth';
// Импортируем компоненты напрямую, если они существуют
import HomeView from '../views/HomeView.vue';
import DashboardView from '../views/DashboardView.vue';
import ProfileView from '../views/ProfileView.vue';
import AdminView from '../views/AdminView.vue'; // Новый компонент для администраторов
import AccessTestView from '../views/AccessTestView.vue';
import ConversationsView from '../views/ConversationsView.vue';
import ChatView from '../views/ChatView.vue';
const routes = [
{
@@ -15,41 +10,12 @@ const routes = [
component: HomeView,
meta: { requiresAuth: false },
},
{
path: '/dashboard',
name: 'Dashboard',
component: () => import('../views/DashboardView.vue'),
meta: { requiresAuth: true, requiresAdmin: true },
},
// Перенаправляем с /chat на главную страницу
{
path: '/chat',
redirect: { name: 'home' },
},
{
path: '/profile',
name: 'profile',
component: ProfileView,
meta: { requiresAuth: true },
},
{
path: '/admin',
name: 'Admin',
component: () => import('../views/AdminView.vue'),
meta: { requiresAdmin: true },
},
{
path: '/access-test',
name: 'access-test',
component: AccessTestView,
meta: { requiresAuth: true, requiresAdmin: true },
},
{
path: '/conversations',
name: 'Conversations',
component: ConversationsView,
meta: { requiresAuth: true },
},
name: 'chat',
component: ChatView,
meta: { requiresAuth: true }
}
];
const router = createRouter({
@@ -63,21 +29,19 @@ const router = createRouter({
// Навигационный хук для проверки аутентификации
router.beforeEach(async (to, from, next) => {
const authStore = useAuthStore();
// Проверяем аутентификацию только если еще не проверяли
if (!authStore.checkPerformed) {
// Проверяем аутентификацию, если она еще не проверена
if (!authStore.isAuthenticated) {
try {
await authStore.checkAuth();
} catch (error) {
console.error('Ошибка при проверке аутентификации:', error);
console.error('Error checking auth:', error);
}
}
// Проверка прав доступа
if (to.meta.requiresAuth && !authStore.isAuthenticated) {
next({ name: 'Home' });
} else if (to.meta.requiresAdmin && !authStore.isAdmin) {
next({ name: 'Home' });
next({ name: 'home' });
} else {
next();
}