From c1477ba77b2b477edbad7fd4b21cc16f870f365c Mon Sep 17 00:00:00 2001 From: TastelessVoid Date: Sat, 21 Feb 2026 19:28:11 +0100 Subject: [PATCH] Fix SW session not updating on account switch (PWA/Electron) --- src/app/pages/client/ClientRoot.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/pages/client/ClientRoot.tsx b/src/app/pages/client/ClientRoot.tsx index 5d4162b0..645b729e 100644 --- a/src/app/pages/client/ClientRoot.tsx +++ b/src/app/pages/client/ClientRoot.tsx @@ -40,6 +40,7 @@ import { AuthMetadataProvider } from '../../hooks/useAuthMetadata'; import { sessionsAtom, activeSessionIdAtom, Session, SessionsAction } from '../../state/sessions'; import { getHomePath } from '../pathUtils'; import { createLogger } from '../../utils/debug'; +import { pushSessionToSW } from '../../../sw-session'; const log = createLogger('ClientRoot'); @@ -181,6 +182,7 @@ export function ClientRoot({ children }: ClientRootProps) { log.log('initClient for', activeSession.userId); const newMx = await initClient(activeSession); loadedUserIdRef.current = activeSession.userId; + pushSessionToSW(activeSession.baseUrl, activeSession.accessToken); return newMx; }, [activeSession, activeSessionId, setActiveSessionId]) ); @@ -193,6 +195,8 @@ export function ClientRoot({ children }: ClientRootProps) { if (!activeSession) return; if (loadedUserIdRef.current && loadedUserIdRef.current !== activeSession.userId) { log.log('session changed from', loadedUserIdRef.current, '→', activeSession.userId, '— reloading client'); + // Update the SW immediately so media requests use the new account's token + pushSessionToSW(activeSession.baseUrl, activeSession.accessToken); if (mx?.clientRunning) { mx.stopClient(); }