fix(secrets): 同机换号继承上一账号的密钥与代理
A 号在桌面端配好密钥后登出,B 号登录时服务端与本地都缺这些配置, 任务只能整批失败。现在登出前把当前账号的明文密钥与代理存进本机 app.json,B 首次加载时只补服务端空缺的模块(fill-only,后台锁定的 代理不覆盖),并写回 B 的本地镜像与 proxy_users;检测状态不继承, 设置页提示逐项点「检测」确认。 同时修掉登出顺序反了的问题:原来先移除 uid 再清镜像,镜像键带 uid,实际删的是 uid=0 的键,A 的明文镜像会留在本机;换号/会话过期 后内存里的 A 明文也会被 B 继续读到。现在先留快照、再清缓存、最后 移除 uid,并在 uid 变化时作废旧会话缓存、给在飞的加载加 epoch 栅栏。
This commit is contained in:
@@ -119,7 +119,7 @@ import { COMPANY_NAME_STORAGE_KEY, writeCompanyIdentity } from '@/shared/auth/co
|
||||
import { clearAccountExpiry, writeAccountExpiry } from '@/shared/auth/account-expiry'
|
||||
import { AUTH_TOKEN_KEY } from '@/shared/auth/session-keys'
|
||||
import { useVersionUpdate } from '@/shared/composables/useVersionUpdate'
|
||||
import { clearApiSecretCache } from '@/shared/utils/api-secret-store'
|
||||
import { captureApiSecretsForInheritance, clearApiSecretCache } from '@/shared/utils/api-secret-store'
|
||||
import UpdateProgressBar from '@/shared/components/UpdateProgressBar.vue'
|
||||
import UpdateLogList from '@/shared/components/UpdateLogList.vue'
|
||||
import VersionPicker from '@/shared/components/VersionPicker.vue'
|
||||
@@ -480,27 +480,33 @@ async function submitLogin() {
|
||||
onMounted(() => {
|
||||
const params = new URLSearchParams(window.location.search || '')
|
||||
if (params.get('logout') === '1' || params.get('switch') === '1') {
|
||||
// 登出/切号:uid 不彻底清除会被路由守卫当“已登录”自动带回首页(见 src/main.ts 守卫)
|
||||
try {
|
||||
window.localStorage.removeItem(AUTH_TOKEN_KEY)
|
||||
window.localStorage.removeItem('uid')
|
||||
window.localStorage.removeItem('username')
|
||||
window.localStorage.removeItem(COMPANY_NAME_STORAGE_KEY)
|
||||
clearAccountExpiry()
|
||||
} catch {
|
||||
/* 忽略 */
|
||||
}
|
||||
// 清空密钥缓存:内存 + 本地镜像(旧 v1 记录保留,供下次登录自动迁移)
|
||||
clearApiSecretCache()
|
||||
// 同步清掉客户端的登录用户标记:Python 端回退到全局/默认代理池
|
||||
try {
|
||||
const bridge = (window as unknown as { pywebview?: { api?: { save_config?: (data: Record<string, unknown>) => Promise<unknown> } } }).pywebview
|
||||
if (bridge?.api && typeof bridge.api.save_config === 'function') {
|
||||
void bridge.api.save_config({ current_uid: '' })
|
||||
const clearSignedOutState = () => {
|
||||
// 清缓存必须在移除 uid 之前:镜像键带 uid,反序会按 uid=0 删错位置,
|
||||
// 把本账号的明文镜像留在磁盘上给下一个账号(或网页脚本)读到。
|
||||
clearApiSecretCache()
|
||||
// 登出/切号:uid 不彻底清除会被路由守卫当“已登录”自动带回首页(见 src/main.ts 守卫)
|
||||
try {
|
||||
window.localStorage.removeItem(AUTH_TOKEN_KEY)
|
||||
window.localStorage.removeItem('uid')
|
||||
window.localStorage.removeItem('username')
|
||||
window.localStorage.removeItem(COMPANY_NAME_STORAGE_KEY)
|
||||
clearAccountExpiry()
|
||||
} catch {
|
||||
/* 忽略 */
|
||||
}
|
||||
// 同步清掉客户端的登录用户标记:Python 端回退到全局/默认代理池
|
||||
try {
|
||||
const bridge = (window as unknown as { pywebview?: { api?: { save_config?: (data: Record<string, unknown>) => Promise<unknown> } } }).pywebview
|
||||
if (bridge?.api && typeof bridge.api.save_config === 'function') {
|
||||
void bridge.api.save_config({ current_uid: '' })
|
||||
}
|
||||
} catch {
|
||||
/* 忽略 */
|
||||
}
|
||||
} catch {
|
||||
/* 忽略 */
|
||||
}
|
||||
// 先把本账号的密钥/代理留给本机下一个账号(桌面端),再清缓存与 uid;
|
||||
// capture 失败也必须照常登出,所以成功/失败两条路都走同一个清理函数。
|
||||
void captureApiSecretsForInheritance().then(clearSignedOutState, clearSignedOutState)
|
||||
// 显式登出/切号后不再自动登录(保留记住的账号,仅关闭自动登录)
|
||||
autoLogin.value = false
|
||||
lsSet(AUTO_LOGIN_KEY, '0')
|
||||
|
||||
@@ -40,6 +40,7 @@ import {
|
||||
getStoredApiSecretSnapshot,
|
||||
listApiSecretModules,
|
||||
loadApiSecrets,
|
||||
takeApiSecretInheritanceNotice,
|
||||
type ApiSecretModuleKey,
|
||||
} from '@/shared/utils/api-secret-store'
|
||||
|
||||
@@ -56,6 +57,16 @@ onMounted(() => {
|
||||
} catch {
|
||||
/* 忽略存储异常 */
|
||||
}
|
||||
const inherited = takeApiSecretInheritanceNotice()
|
||||
if (inherited) {
|
||||
const labels = listApiSecretModules()
|
||||
.filter((module) => inherited.moduleKeys.includes(module.moduleKey))
|
||||
.map((module) => module.moduleLabel)
|
||||
if (inherited.proxy) labels.push('代理设置')
|
||||
hint.value = labels.length
|
||||
? `已继承本机账号「${inherited.fromUsername || inherited.fromUid}」的${labels.join('、')},请点击上方对应模块的「检测」确认后保存进入。`
|
||||
: `已继承本机账号「${inherited.fromUsername || inherited.fromUid}」的密钥配置,请点击上方「检测」逐项确认后保存进入。`
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user