1.3
This commit is contained in:
@@ -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()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user