fix(web): recheck setup status after page reload (#6968)

This commit is contained in:
Seefs
2026-08-29 19:24:14 +08:00
committed by GitHub
parent 0f2a2075ab
commit 98d50d5383
+7 -35
View File
@@ -107,37 +107,8 @@ function RootComponent() {
) )
} }
// 缓存 setup 状态检查结果,避免每次导航都重复调用 API // 同一页面会话内避免重复检查;刷新后重新校验当前服务实例。
// 使用 localStorage 持久化,避免页面刷新后重复检查 let setupStatusChecked = false
const SETUP_CHECKED_KEY = 'setup_status_checked'
function getSetupStatusFromCache(): boolean {
try {
if (typeof window !== 'undefined') {
return window.localStorage.getItem(SETUP_CHECKED_KEY) === 'true'
}
} catch {
/* empty */
}
return false
}
function setSetupStatusCache(value: boolean): void {
try {
if (typeof window !== 'undefined') {
if (value) {
window.localStorage.setItem(SETUP_CHECKED_KEY, 'true')
} else {
window.localStorage.removeItem(SETUP_CHECKED_KEY)
}
}
} catch {
/* empty */
}
}
// 内存中的标记,避免同一会话中重复检查
let setupStatusChecked = getSetupStatusFromCache()
export const Route = createRootRouteWithContext<{ export const Route = createRootRouteWithContext<{
queryClient: QueryClient queryClient: QueryClient
@@ -167,11 +138,12 @@ export const Route = createRootRouteWithContext<{
authBootstrap, authBootstrap,
]) ])
if (status?.success && status.data && !status.data.status) { if (status?.success && status.data) {
throw redirect({ to: '/setup' }) if (!status.data.status) {
throw redirect({ to: '/setup' })
}
setupStatusChecked = true
} }
setupStatusChecked = true
setSetupStatusCache(true)
} else { } else {
await authBootstrap await authBootstrap
} }