41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
|
|
import { useAuthStore } from '@/stores/auth'
|
|
|
|
const routes: RouteRecordRaw[] = [
|
|
{ path: '/login', component: () => import('@/views/Login.vue'), meta: { layout: 'blank' } },
|
|
{
|
|
path: '/',
|
|
component: () => import('@/components/AppLayout.vue'),
|
|
meta: { requiresAuth: true },
|
|
children: [
|
|
{ path: '', component: () => import('@/views/Feed.vue') },
|
|
{ path: 'article/:id', component: () => import('@/views/ArticleDetail.vue') },
|
|
{ path: 'sources', component: () => import('@/views/Sources.vue') },
|
|
{ path: 'bookmarks', component: () => import('@/views/Bookmarks.vue') },
|
|
{ path: 'admin/sources', component: () => import('@/views/AdminSources.vue'), meta: { ownerOnly: true } },
|
|
{ path: 'admin/llm', component: () => import('@/views/AdminLlmSettings.vue'), meta: { ownerOnly: true } },
|
|
],
|
|
},
|
|
]
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes,
|
|
})
|
|
|
|
router.beforeEach((to) => {
|
|
const auth = useAuthStore()
|
|
auth.restore()
|
|
if (to.meta.requiresAuth && !auth.isLogged) {
|
|
return { path: '/login', query: { next: to.fullPath } }
|
|
}
|
|
if (to.meta.ownerOnly && !auth.isOwner) {
|
|
return { path: '/' }
|
|
}
|
|
if (to.path === '/login' && auth.isLogged) {
|
|
return { path: '/' }
|
|
}
|
|
})
|
|
|
|
export default router
|