38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
import { useAuthStore } from '../stores/auth'
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes: [
|
|
{ path: '/login', component: () => import('../views/Login.vue') },
|
|
{
|
|
path: '/admin',
|
|
component: () => import('../views/admin/Layout.vue'),
|
|
children: [
|
|
{ path: 'queries', component: () => import('../views/admin/Queries.vue') },
|
|
{ path: 'tables', component: () => import('../views/admin/Tables.vue') },
|
|
{ path: 'users', component: () => import('../views/admin/Users.vue') },
|
|
{ path: 'permissions', component: () => import('../views/admin/Permissions.vue') },
|
|
{ path: 'blacklist', component: () => import('../views/admin/Blacklist.vue') },
|
|
{ path: 'api-keys', component: () => import('../views/admin/ApiKeys.vue') },
|
|
{ path: 'cache', component: () => import('../views/admin/Cache.vue') },
|
|
{ path: 'cors', component: () => import('../views/admin/Cors.vue') },
|
|
{ path: 'cdn', component: () => import('../views/admin/Cdn.vue') },
|
|
],
|
|
meta: { requiresAuth: true },
|
|
},
|
|
{ path: '/', redirect: '/admin/queries' },
|
|
],
|
|
})
|
|
|
|
router.beforeEach((to) => {
|
|
const auth = useAuthStore()
|
|
if (to.meta.requiresAuth && !auth.isAuthenticated) {
|
|
return '/login'
|
|
}
|
|
if (to.path === '/login' && auth.isAuthenticated) {
|
|
return '/admin/queries'
|
|
}
|
|
})
|
|
|
|
export default router
|