fix(frontend): restore pending auth session flow
This commit is contained in:
@@ -341,6 +341,16 @@ const routes: RouteRecordRaw[] = [
|
||||
descriptionKey: 'admin.users.description'
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/admin/users/auth-identity-migration-reports',
|
||||
name: 'AdminAuthIdentityMigrationReports',
|
||||
component: () => import('@/views/admin/AuthIdentityMigrationReportsView.vue'),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
requiresAdmin: true,
|
||||
title: 'Auth Identity Migration Reports'
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/admin/groups',
|
||||
name: 'AdminGroups',
|
||||
@@ -538,6 +548,29 @@ const navigationLoading = useNavigationLoadingState()
|
||||
// 延迟初始化预加载,传入 router 实例
|
||||
let routePrefetch: ReturnType<typeof useRoutePrefetch> | null = null
|
||||
const BACKEND_MODE_ALLOWED_PATHS = ['/login', '/key-usage', '/setup']
|
||||
const BACKEND_MODE_CALLBACK_PATHS = [
|
||||
'/auth/callback',
|
||||
'/auth/linuxdo/callback',
|
||||
'/auth/oidc/callback',
|
||||
'/auth/wechat/callback'
|
||||
]
|
||||
const BACKEND_MODE_PENDING_AUTH_PATHS = ['/register', '/email-verify']
|
||||
|
||||
function isBackendModePublicRouteAllowed(path: string, hasPendingAuthSession: boolean): boolean {
|
||||
if (BACKEND_MODE_ALLOWED_PATHS.some((allowedPath) => path === allowedPath || path.startsWith(allowedPath))) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (BACKEND_MODE_CALLBACK_PATHS.some((callbackPath) => path === callbackPath)) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (hasPendingAuthSession && BACKEND_MODE_PENDING_AUTH_PATHS.some((allowedPath) => path === allowedPath)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
router.beforeEach((to, _from, next) => {
|
||||
// 开始导航加载状态
|
||||
@@ -590,7 +623,7 @@ router.beforeEach((to, _from, next) => {
|
||||
}
|
||||
// Backend mode: block public pages for unauthenticated users (except login, key-usage, setup)
|
||||
if (appStore.backendModeEnabled && !authStore.isAuthenticated) {
|
||||
const isAllowed = BACKEND_MODE_ALLOWED_PATHS.some((p) => to.path === p || to.path.startsWith(p))
|
||||
const isAllowed = isBackendModePublicRouteAllowed(to.path, authStore.hasPendingAuthSession)
|
||||
if (!isAllowed) {
|
||||
next('/login')
|
||||
return
|
||||
@@ -650,7 +683,7 @@ router.beforeEach((to, _from, next) => {
|
||||
next()
|
||||
return
|
||||
}
|
||||
const isAllowed = BACKEND_MODE_ALLOWED_PATHS.some((p) => to.path === p || to.path.startsWith(p))
|
||||
const isAllowed = isBackendModePublicRouteAllowed(to.path, authStore.hasPendingAuthSession)
|
||||
if (!isAllowed) {
|
||||
next('/login')
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user