fix: infinite jump to login url (#27178)

This commit is contained in:
Joel
2025-10-21 13:25:20 +08:00
committed by GitHub
parent ff9b74efeb
commit fb6f05c267

View File

@@ -114,6 +114,15 @@ export type IOtherOptions = {
onDataSourceNodeError?: IOnDataSourceNodeError onDataSourceNodeError?: IOnDataSourceNodeError
} }
function jumpTo(url: string) {
if(!url)
return
const targetPath = new URL(url, globalThis.location.origin).pathname
if(targetPath === globalThis.location.pathname)
return
globalThis.location.href = url
}
function unicodeToChar(text: string) { function unicodeToChar(text: string) {
if (!text) if (!text)
return '' return ''
@@ -576,11 +585,11 @@ export const request = async<T>(url: string, options = {}, otherOptions?: IOther
return Promise.reject(err) return Promise.reject(err)
} }
if (code === 'not_init_validated' && IS_CE_EDITION) { if (code === 'not_init_validated' && IS_CE_EDITION) {
globalThis.location.href = `${globalThis.location.origin}${basePath}/init` jumpTo(`${globalThis.location.origin}${basePath}/init`)
return Promise.reject(err) return Promise.reject(err)
} }
if (code === 'not_setup' && IS_CE_EDITION) { if (code === 'not_setup' && IS_CE_EDITION) {
globalThis.location.href = `${globalThis.location.origin}${basePath}/install` jumpTo(`${globalThis.location.origin}${basePath}/install`)
return Promise.reject(err) return Promise.reject(err)
} }
@@ -589,15 +598,14 @@ export const request = async<T>(url: string, options = {}, otherOptions?: IOther
if (refreshErr === null) if (refreshErr === null)
return baseFetch<T>(url, options, otherOptionsForBaseFetch) return baseFetch<T>(url, options, otherOptionsForBaseFetch)
if (location.pathname !== `${basePath}/signin` || !IS_CE_EDITION) { if (location.pathname !== `${basePath}/signin` || !IS_CE_EDITION) {
globalThis.location.href = loginUrl jumpTo(loginUrl)
return Promise.reject(err) return Promise.reject(err)
} }
if (!silent) { if (!silent) {
Toast.notify({ type: 'error', message }) Toast.notify({ type: 'error', message })
return Promise.reject(err) return Promise.reject(err)
} }
if (globalThis.location.href !== loginUrl) jumpTo(loginUrl)
globalThis.location.href = loginUrl
return Promise.reject(err) return Promise.reject(err)
} }
else { else {