up
This commit is contained in:
@@ -7,11 +7,12 @@ import Users from '../views/Users.vue'
|
||||
import Restaurants from '../views/Restaurants.vue'
|
||||
import AdminSettings from '../views/AdminSettings.vue'
|
||||
import NotFound from '../views/NotFound.vue'
|
||||
import { useSettingsStore } from '../stores/settings'
|
||||
|
||||
const routes = [
|
||||
{ path: '/login', component: Login, meta: { title: 'Login' } },
|
||||
{ path: '/register', component: Register, meta: { title: 'Register' } },
|
||||
{ path: '/setup', component: Setup, meta: { title: 'Setup' } },
|
||||
{ path: '/login', component: Login, meta: { title: 'Login', requiresAuth: false } },
|
||||
{ path: '/register', component: Register, meta: { title: 'Register', requiresAuth: false } },
|
||||
{ path: '/setup', component: Setup, meta: { title: 'Setup', requiresAuth: false } },
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/dashboard'
|
||||
@@ -50,14 +51,20 @@ const router = createRouter({
|
||||
})
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
// Update page title
|
||||
document.title = `${to.meta.title || 'Admin Panel'} | AdminPanel`
|
||||
// Загружаем настройки приложения, если они ещё не загружены
|
||||
const settings = useSettingsStore()
|
||||
if (!settings.siteName) {
|
||||
await settings.loadSettings()
|
||||
}
|
||||
|
||||
// Check if setup is needed
|
||||
// Устанавливаем заголовок страницы с использованием site_name
|
||||
const pageTitle = to.meta.title ? `${to.meta.title} | ${settings.siteName}` : settings.siteName
|
||||
document.title = pageTitle
|
||||
|
||||
// Проверка необходимости установки (setup)
|
||||
try {
|
||||
const statusRes = await fetch('/api/status')
|
||||
const status = await statusRes.json()
|
||||
|
||||
if (status.needsSetup && to.path !== '/setup') {
|
||||
next('/setup')
|
||||
return
|
||||
@@ -66,21 +73,29 @@ router.beforeEach(async (to, from, next) => {
|
||||
console.error('Failed to check status', e)
|
||||
}
|
||||
|
||||
// Проверка, что залогиненный пользователь не может зайти на страницу логина
|
||||
if (to.path === '/login') {
|
||||
try {
|
||||
const meRes = await fetch('/api/admin/me');
|
||||
const meRes = await fetch('/api/admin/me')
|
||||
if (meRes.ok) {
|
||||
next('/dashboard');
|
||||
return;
|
||||
next('/dashboard')
|
||||
return
|
||||
}
|
||||
} catch (e) {
|
||||
// игнорируем ошибку, продолжаем
|
||||
}
|
||||
}
|
||||
|
||||
// Check authentication
|
||||
const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
|
||||
// Проверка доступности регистрации
|
||||
if (to.path === '/register') {
|
||||
if (!settings.enableRegistration) {
|
||||
next('/login')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Проверка аутентификации для защищённых маршрутов
|
||||
const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
|
||||
if (requiresAuth) {
|
||||
try {
|
||||
const res = await fetch('/api/admin/me')
|
||||
|
||||
Reference in New Issue
Block a user