Merge pull request #2 from TastelessVoid/dev

Fix SW session not updating on account switch (PWA/Electron)
This commit is contained in:
7w1 authored and GitHub committed 2026-02-21 12:32:20 -06:00
commit c127c778ff
1 file changed
+4
+4
View File
@@ -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();
}