feat(router): implement auto-setup failure handling for Lite edition
- Added logic to track auto-setup failures using localStorage, preventing repeated attempts if the setup fails. - Updated the router's authentication flow to conditionally attempt auto-setup based on the failure status. - Enhanced the login component to check for auto-setup failure before attempting the setup process. This update improves the user experience by ensuring that failed auto-setup attempts do not lead to repeated failures during login.
This commit is contained in:
@@ -5,6 +5,15 @@ import { autoSetup } from '@/api/auth'
|
|||||||
|
|
||||||
/** Lite /桌面 WebView 硬刷新时可能只打开 `/`,用 session 记住上次页面以便恢复 */
|
/** Lite /桌面 WebView 硬刷新时可能只打开 `/`,用 session 记住上次页面以便恢复 */
|
||||||
const LITE_LAST_PATH_KEY = 'weknora_lite_last_path'
|
const LITE_LAST_PATH_KEY = 'weknora_lite_last_path'
|
||||||
|
const AUTO_SETUP_FAILED_KEY = 'weknora_auto_setup_failed'
|
||||||
|
|
||||||
|
function shouldTryAutoSetup() {
|
||||||
|
return localStorage.getItem(AUTO_SETUP_FAILED_KEY) !== 'true'
|
||||||
|
}
|
||||||
|
|
||||||
|
function markAutoSetupFailed() {
|
||||||
|
localStorage.setItem(AUTO_SETUP_FAILED_KEY, 'true')
|
||||||
|
}
|
||||||
|
|
||||||
function isLiteEdition(authStore: ReturnType<typeof useAuthStore>) {
|
function isLiteEdition(authStore: ReturnType<typeof useAuthStore>) {
|
||||||
return authStore.isLiteMode || localStorage.getItem('weknora_lite_mode') === 'true'
|
return authStore.isLiteMode || localStorage.getItem('weknora_lite_mode') === 'true'
|
||||||
@@ -188,8 +197,7 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
// 检查用户认证状态
|
// 检查用户认证状态
|
||||||
if (to.meta.requiresAuth !== false) {
|
if (to.meta.requiresAuth !== false) {
|
||||||
if (!authStore.isLoggedIn) {
|
if (!authStore.isLoggedIn) {
|
||||||
// Lite 版:尝试自动初始化(仅一次),成功则跳过登录页
|
if (!autoSetupAttempted && shouldTryAutoSetup()) {
|
||||||
if (!autoSetupAttempted) {
|
|
||||||
autoSetupAttempted = true
|
autoSetupAttempted = true
|
||||||
try {
|
try {
|
||||||
const response = await autoSetup()
|
const response = await autoSetup()
|
||||||
@@ -198,9 +206,11 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
authStore.setLiteMode(true)
|
authStore.setLiteMode(true)
|
||||||
next(to.fullPath)
|
next(to.fullPath)
|
||||||
return
|
return
|
||||||
|
} else {
|
||||||
|
markAutoSetupFailed()
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// auto-setup 不可用(非 lite 版本),走正常登录流程
|
markAutoSetupFailed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next('/login')
|
next('/login')
|
||||||
|
|||||||
@@ -675,15 +675,20 @@ onMounted(async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const AUTO_SETUP_FAILED_KEY = 'weknora_auto_setup_failed'
|
||||||
const response = await autoSetup()
|
if (localStorage.getItem(AUTO_SETUP_FAILED_KEY) !== 'true') {
|
||||||
if (response.success) {
|
try {
|
||||||
authStore.setLiteMode(true)
|
const response = await autoSetup()
|
||||||
await persistLoginResponse(response)
|
if (response.success) {
|
||||||
return
|
authStore.setLiteMode(true)
|
||||||
|
await persistLoginResponse(response)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
localStorage.setItem(AUTO_SETUP_FAILED_KEY, 'true')
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
localStorage.setItem(AUTO_SETUP_FAILED_KEY, 'true')
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
// auto-setup not available (standard edition) — show normal login form
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadOIDCConfig()
|
loadOIDCConfig()
|
||||||
|
|||||||
Reference in New Issue
Block a user