Add transfer tracking and secure admin access
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
import { adminAuth } from '../auth'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes: [
|
||||
{ path: '/login', name: 'Login', component: () => import('../views/Login.vue'), meta: { public: true } },
|
||||
{ path: '/change-password', name: 'ChangePassword', component: () => import('../views/ChangePassword.vue') },
|
||||
{ path: '/', redirect: '/dashboard' },
|
||||
{ path: '/dashboard', name: 'Dashboard', component: () => import('../views/Dashboard.vue') },
|
||||
{ path: '/settings', name: 'Settings', component: () => import('../views/Settings.vue') },
|
||||
@@ -13,7 +16,24 @@ const router = createRouter({
|
||||
{ path: '/stickers', name: 'Stickers', component: () => import('../views/Stickers.vue') },
|
||||
{ path: '/users', name: 'Users', component: () => import('../views/Users.vue') },
|
||||
{ path: '/push', name: 'PushCampaigns', component: () => import('../views/PushCampaigns.vue') },
|
||||
{ path: '/admin-accounts', name: 'AdminAccounts', component: () => import('../views/AdminAccounts.vue'), meta: { role: 'super_admin' } },
|
||||
{ path: '/audit', name: 'Audit', component: () => import('../views/Audit.vue'), meta: { role: 'super_admin' } },
|
||||
],
|
||||
})
|
||||
|
||||
router.beforeEach(async to => {
|
||||
if (to.meta.public) {
|
||||
if (to.name === 'Login' && await adminAuth.ensure()) {
|
||||
return adminAuth.identity.value?.mustChangePassword ? '/change-password' : '/dashboard'
|
||||
}
|
||||
return true
|
||||
}
|
||||
if (!await adminAuth.ensure()) return { name: 'Login', query: { redirect: to.fullPath } }
|
||||
const user = adminAuth.identity.value!
|
||||
if (user.mustChangePassword && to.name !== 'ChangePassword') return { name: 'ChangePassword' }
|
||||
if (!user.mustChangePassword && to.name === 'ChangePassword') return { name: 'Dashboard' }
|
||||
if (to.meta.role && to.meta.role !== user.role) return { name: 'Dashboard' }
|
||||
return true
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user