mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-12 15:21:09 +00:00
fix(web): recheck setup status after page reload (#6968)
This commit is contained in:
@@ -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) {
|
||||||
|
if (!status.data.status) {
|
||||||
throw redirect({ to: '/setup' })
|
throw redirect({ to: '/setup' })
|
||||||
}
|
}
|
||||||
setupStatusChecked = true
|
setupStatusChecked = true
|
||||||
setSetupStatusCache(true)
|
}
|
||||||
} else {
|
} else {
|
||||||
await authBootstrap
|
await authBootstrap
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user