feature: Digitization Workstation UI
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
|
||||
import { useAuthStore, getDefaultRouteForRole } from '../stores/auth'
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
component: () => import('../views/LoginView.vue'),
|
||||
meta: { requiresAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/intake',
|
||||
name: 'Intake',
|
||||
component: () => import('../views/IntakeView.vue'),
|
||||
meta: { requiresAuth: true, roles: ['INTAKE_CLERK', 'ADMINISTRATOR'] },
|
||||
},
|
||||
{
|
||||
path: '/entry',
|
||||
name: 'EntryQueue',
|
||||
component: () => import('../views/EntryView.vue'),
|
||||
meta: { requiresAuth: true, roles: ['DATA_ENTRY_CLERK', 'ADMINISTRATOR'] },
|
||||
},
|
||||
{
|
||||
path: '/entry/:batchId',
|
||||
name: 'EntryBatch',
|
||||
component: () => import('../views/EntryView.vue'),
|
||||
meta: { requiresAuth: true, roles: ['DATA_ENTRY_CLERK', 'ADMINISTRATOR'] },
|
||||
props: true,
|
||||
},
|
||||
{
|
||||
path: '/verification',
|
||||
name: 'VerificationQueue',
|
||||
component: () => import('../views/VerificationView.vue'),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
roles: ['VERIFIER', 'CLINICAL_APPROVER', 'ADMINISTRATOR'],
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/verification/:batchId',
|
||||
name: 'VerificationBatch',
|
||||
component: () => import('../views/VerificationView.vue'),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
roles: ['VERIFIER', 'CLINICAL_APPROVER', 'ADMINISTRATOR'],
|
||||
},
|
||||
props: true,
|
||||
},
|
||||
{
|
||||
path: '/dashboard',
|
||||
name: 'Dashboard',
|
||||
component: () => import('../views/QueueDashboardView.vue'),
|
||||
meta: { requiresAuth: true, roles: ['ADMINISTRATOR'] },
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/login',
|
||||
},
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes,
|
||||
})
|
||||
|
||||
// Navigation guard: check auth and role
|
||||
router.beforeEach((to, _from, next) => {
|
||||
const auth = useAuthStore()
|
||||
|
||||
if (to.path === '/login' && auth.isAuthenticated) {
|
||||
return next(getDefaultRouteForRole(auth.userRole))
|
||||
}
|
||||
|
||||
if (to.meta.requiresAuth && !auth.isAuthenticated) {
|
||||
return next('/login')
|
||||
}
|
||||
|
||||
if (to.meta.roles && Array.isArray(to.meta.roles)) {
|
||||
const allowedRoles = to.meta.roles as string[]
|
||||
if (!allowedRoles.includes(auth.userRole)) {
|
||||
const fallback = getDefaultRouteForRole(auth.userRole)
|
||||
if (fallback !== '/login' && fallback !== to.path) {
|
||||
return next(fallback)
|
||||
}
|
||||
return next('/login')
|
||||
}
|
||||
}
|
||||
|
||||
next()
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user