48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
import { useAuthStore } from '@/stores/auth'
|
|
|
|
const routes = [
|
|
{ path: '/', redirect: '/me' },
|
|
{
|
|
path: '/login',
|
|
name: 'login',
|
|
component: () => import('@/pages/LoginPage.vue')
|
|
},
|
|
{
|
|
path: '/auth/callback',
|
|
name: 'auth-callback',
|
|
component: () => import('@/pages/AuthCallbackPage.vue')
|
|
},
|
|
{
|
|
path: '/me',
|
|
name: 'me',
|
|
component: () => import('@/pages/profile/MePage.vue'),
|
|
meta: { requiresAuth: true }
|
|
},
|
|
{
|
|
path: '/me/permissions',
|
|
name: 'my-permissions',
|
|
component: () => import('@/pages/permissions/PermissionSnapshotPage.vue'),
|
|
meta: { requiresAuth: true }
|
|
},
|
|
{
|
|
path: '/admin/permissions',
|
|
name: 'admin-permissions',
|
|
component: () => import('@/pages/permissions/PermissionAdminPage.vue')
|
|
}
|
|
]
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes
|
|
})
|
|
|
|
router.beforeEach((to) => {
|
|
const authStore = useAuthStore()
|
|
if (to.meta.requiresAuth && !authStore.isLoggedIn) {
|
|
return { name: 'login', query: { redirect: to.fullPath } }
|
|
}
|
|
})
|
|
|
|
export default router
|