Files
trade/web/frontend/src/router/index.ts

73 lines
1.7 KiB
TypeScript

import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
const routes: RouteRecordRaw[] = [
{
path: '/login',
name: 'login',
component: () => import('@/views/LoginView.vue'),
meta: { layout: 'blank', public: true },
},
{
path: '/change-password',
name: 'change-password',
component: () => import('@/views/ChangePasswordView.vue'),
meta: { layout: 'blank' },
},
{ path: '/', redirect: '/scores' },
{
path: '/scores',
name: 'scores',
component: () => import('@/views/ScoresView.vue'),
},
{
path: '/chart',
name: 'chart',
component: () => import('@/views/ChartView.vue'),
},
{
path: '/contract-full',
name: 'contract-full',
component: () => import('@/views/ContractFullView.vue'),
},
{
path: '/run',
name: 'run',
component: () => import('@/views/RunView.vue'),
},
{
path: '/daily-direction',
name: 'daily-direction',
component: () => import('@/views/DailyDirectionView.vue'),
},
{
path: '/admin/users',
name: 'admin-users',
component: () => import('@/views/AdminUsersView.vue'),
meta: { adminOnly: true },
},
{ path: '/:pathMatch(.*)*', redirect: '/scores' },
]
const router = createRouter({
history: createWebHistory(),
routes,
})
router.beforeEach((to) => {
const auth = useAuthStore()
if (to.meta.public) return true
if (!auth.token) {
return { path: '/login', query: { redirect: to.fullPath } }
}
if (auth.requirePasswordChange && to.path !== '/change-password') {
return { path: '/change-password' }
}
if (to.meta.adminOnly && !auth.isAdmin) {
return { path: '/scores' }
}
return true
})
export default router