fix(stage-ui/auth): prevent multiple syncs and ensure providers are only set if not already configured

This commit is contained in:
RainbowBird
2026-03-28 02:25:44 +08:00
committed by RainbowBird
parent 2f730ef93a
commit 1645d2a475
2 changed files with 27 additions and 8 deletions
@@ -30,7 +30,16 @@ export function useAuthProviderSync() {
const speechStore = useSpeechStore()
const hearingStore = useHearingStore()
// Track whether the sync has already fired in this session to avoid
// re-running on every page navigation (onAuthenticated fires immediately
// if already logged in when the hook is registered).
let hasSynced = false
authStore.onAuthenticated(async () => {
if (hasSynced)
return
hasSynced = true
const toActivate = AUTH_ACTIVATED_PROVIDERS.filter(
p => providersStore.getProviderMetadata(p.id) != null,
)
@@ -39,19 +48,27 @@ export function useAuthProviderSync() {
providersStore.forceProviderConfigured(id)
}
// Only set official provider as active when the user hasn't configured
// any provider for that module yet.
for (const { id, module } of toActivate) {
switch (module) {
case 'consciousness':
consciousnessStore.activeProvider = id
consciousnessStore.activeModel = 'auto'
if (!consciousnessStore.activeProvider) {
consciousnessStore.activeProvider = id
consciousnessStore.activeModel = 'auto'
}
break
case 'speech':
speechStore.activeSpeechProvider = id
speechStore.activeSpeechModel = 'auto'
if (!speechStore.activeSpeechProvider) {
speechStore.activeSpeechProvider = id
speechStore.activeSpeechModel = 'auto'
}
break
case 'hearing':
hearingStore.activeTranscriptionProvider = id
hearingStore.activeTranscriptionModel = 'auto'
if (!hearingStore.activeTranscriptionProvider) {
hearingStore.activeTranscriptionProvider = id
hearingStore.activeTranscriptionModel = 'auto'
}
break
}
}
@@ -72,6 +89,8 @@ export function useAuthProviderSync() {
})
authStore.onLogout(() => {
hasSynced = false
for (const { id } of AUTH_ACTIVATED_PROVIDERS) {
providersStore.setProviderUnconfigured(id)
}
+2 -2
View File
@@ -523,7 +523,7 @@ importers:
version: 1.3.0(@hono/node-server@1.19.11(hono@4.11.3))(bufferutil@4.1.0)(hono@4.11.3)(utf-8-validate@5.0.10)
'@moeru/eventa':
specifier: 'catalog:'
version: 1.0.0-beta.2(electron@41.0.3)(h3@2.0.1-rc.19(crossws@0.4.4(srvx@0.11.13(patch_hash=c761d25a70e22a0925c88fe91a9dd1c3153dd341d8fd4f260166678156c4df2d))))
version: 1.0.0-beta.2(electron@41.0.3)
'@moeru/std':
specifier: 'catalog:'
version: 0.1.0-beta.17
@@ -2298,7 +2298,7 @@ importers:
dependencies:
'@moeru/eventa':
specifier: 'catalog:'
version: 1.0.0-beta.2(electron@41.0.3)(h3@2.0.1-rc.19(crossws@0.4.4(srvx@0.11.13(patch_hash=c761d25a70e22a0925c88fe91a9dd1c3153dd341d8fd4f260166678156c4df2d))))
version: 1.0.0-beta.2(electron@41.0.3)
packages/server-shared:
dependencies: