From 1645d2a475c96b42dd05455a847c735967d53213 Mon Sep 17 00:00:00 2001 From: RainbowBird Date: Sat, 28 Mar 2026 02:09:28 +0800 Subject: [PATCH] fix(stage-ui/auth): prevent multiple syncs and ensure providers are only set if not already configured --- .../src/composables/use-auth-provider-sync.ts | 31 +++++++++++++++---- pnpm-lock.yaml | 4 +-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/stage-ui/src/composables/use-auth-provider-sync.ts b/packages/stage-ui/src/composables/use-auth-provider-sync.ts index 491177e48..16d8fe5c7 100644 --- a/packages/stage-ui/src/composables/use-auth-provider-sync.ts +++ b/packages/stage-ui/src/composables/use-auth-provider-sync.ts @@ -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) } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d507f1b2e..64bdd15ec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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: