Reset api_key from env defaults on server select to clear stale keys

This commit is contained in:
Warren
2026-05-20 15:53:40 +08:00
parent e5985e625d
commit b8ac27f9bb

View File

@@ -143,21 +143,27 @@ const customUrl = ref('')
const selectedUrl = ref('')
function initSelectedServer() {
// Reset api_key from env defaults to clear any stale key
localStorage.removeItem('portal_config')
const config = getCurrentConfig()
const currentUrl = config.api_base_url
const matched = serverPresets.find(s => s.url === currentUrl)
if (matched) {
selectedUrl.value = matched.url
showCustomUrl.value = false
saveConfig({ ...config, api_base_url: matched.url })
} else {
selectedUrl.value = currentUrl
customUrl.value = currentUrl
showCustomUrl.value = true
saveConfig({ ...config })
}
}
function selectServer(srv: ServerPreset) {
selectedUrl.value = srv.url
// Reset api_key from env to avoid using a stale key
localStorage.removeItem('portal_config')
const config = getCurrentConfig()
saveConfig({ ...config, api_base_url: srv.url })
}
@@ -178,6 +184,8 @@ function toggleCustom() {
function onCustomUrlInput() {
selectedUrl.value = customUrl.value
// Reset api_key from env
localStorage.removeItem('portal_config')
const config = getCurrentConfig()
saveConfig({ ...config, api_base_url: customUrl.value })
}
@@ -199,6 +207,7 @@ const handleLogin = async () => {
let apiUrl = selectedUrl.value
if (showCustomUrl.value && customUrl.value) {
apiUrl = customUrl.value
localStorage.removeItem('portal_config')
const config = getCurrentConfig()
saveConfig({ ...config, api_base_url: customUrl.value })
}