This commit is contained in:
2026-06-13 08:37:28 +08:00
parent ddc90e4b0d
commit ebcfb0c258
5 changed files with 204 additions and 51 deletions
+7 -1
View File
@@ -135,7 +135,7 @@ const routes: RouteRecordRaw[] = [
{
path: '/admin',
component: () => import('@/layouts/AdminLayout.vue'),
meta: { requiresAuth: true },
meta: { requiresAuth: true, requiresAdmin: true },
children: [
{ path: '', redirect: '/admin/dashboard' },
{ path: 'dashboard', name: 'AdminDashboard', component: () => import('@/views/admin/AdminDashboardView.vue') },
@@ -165,12 +165,18 @@ router.beforeEach(async (to, _from, next) => {
}
const needsAuth = to.matched.some((record) => record.meta.requiresAuth)
const needsAdmin = to.matched.some((record) => record.meta.requiresAdmin)
if (needsAuth && !authStore.isAuthenticated) {
next({ name: 'Login', query: { redirect: to.fullPath } })
return
}
if (needsAdmin && !authStore.user?.is_admin && !localStorage.getItem('admin_token')) {
next({ name: 'ChatList' })
return
}
next()
})