mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
Route audit admins into admin console
This commit is contained in:
@@ -117,7 +117,7 @@ async function syncExternalAuthState(nextToken: string | null): Promise<void> {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (router.currentRoute.value.path.startsWith('/admin') && user.role !== 'admin') {
|
if (router.currentRoute.value.path.startsWith('/admin') && !authStore.canAccessAdmin) {
|
||||||
await router.replace('/dashboard')
|
await router.replace('/dashboard')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ async function handleLogin() {
|
|||||||
// 延迟一下让用户看到成功消息
|
// 延迟一下让用户看到成功消息
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// 根据用户角色跳转到不同的仪表盘
|
// 根据用户角色跳转到不同的仪表盘
|
||||||
const targetPath = authStore.user?.role === 'admin' ? '/admin/dashboard' : '/dashboard'
|
const targetPath = authStore.canAccessAdmin ? '/admin/dashboard' : '/dashboard'
|
||||||
router.push(targetPath)
|
router.push(targetPath)
|
||||||
}, 1000)
|
}, 1000)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ export async function checkAdminAccess(
|
|||||||
authStore: ReturnType<typeof useAuthStore>,
|
authStore: ReturnType<typeof useAuthStore>,
|
||||||
moduleStore: ReturnType<typeof useModuleStore>
|
moduleStore: ReturnType<typeof useModuleStore>
|
||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
const isAdmin = authStore.user?.role === 'admin'
|
if (!authStore.canAccessAdmin) {
|
||||||
if (!isAdmin) {
|
|
||||||
log.warn('Non-admin user attempted to access admin page, redirecting to user dashboard')
|
log.warn('Non-admin user attempted to access admin page, redirecting to user dashboard')
|
||||||
return '/dashboard'
|
return '/dashboard'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,12 +26,11 @@ export function resolveHomeRedirect(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 已登录用户首次访问首页(非返回/刷新场景),根据角色跳转到对应仪表盘
|
// 已登录用户首次访问首页(非返回/刷新场景),根据角色跳转到对应仪表盘
|
||||||
const isAdmin = authStore.user?.role === 'admin'
|
|
||||||
const redirectPath = sessionStorage.getItem('redirectPath')
|
const redirectPath = sessionStorage.getItem('redirectPath')
|
||||||
if (redirectPath && redirectPath !== '/') {
|
if (redirectPath && redirectPath !== '/') {
|
||||||
sessionStorage.removeItem('redirectPath')
|
sessionStorage.removeItem('redirectPath')
|
||||||
return redirectPath
|
return redirectPath
|
||||||
}
|
}
|
||||||
|
|
||||||
return isAdmin ? '/admin/dashboard' : '/dashboard'
|
return authStore.canAccessAdmin ? '/admin/dashboard' : '/dashboard'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user