fix(web): disconnect keeps token alive — reconnect without re-auth
This commit is contained in:
@@ -425,10 +425,10 @@ export const useInstanceStore = create<InstanceState>((set, get) => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
disconnectInstance: (origin: string) => {
|
disconnectInstance: (origin: string) => {
|
||||||
// Tear down WebSocket connection
|
// Tear down WebSocket connection (stops auto-reconnect)
|
||||||
disconnectWs(origin);
|
disconnectWs(origin);
|
||||||
|
|
||||||
// Update registry entry to disconnected (preserve the entry)
|
// Update registry entry to disconnected
|
||||||
const registry = upsertRegistryEntry(get().registry, origin, {
|
const registry = upsertRegistryEntry(get().registry, origin, {
|
||||||
origin,
|
origin,
|
||||||
status: 'disconnected',
|
status: 'disconnected',
|
||||||
@@ -437,17 +437,16 @@ export const useInstanceStore = create<InstanceState>((set, get) => ({
|
|||||||
});
|
});
|
||||||
const registryUpdatedAt = Date.now();
|
const registryUpdatedAt = Date.now();
|
||||||
|
|
||||||
// Save the token BEFORE filtering it out of instances — this preserves
|
// Keep the instance in the array with status 'disconnected' — preserves
|
||||||
// the cached token in localStorage so reconnectInstance can restore it later.
|
// the token and API client so reconnect is instant (no re-auth needed).
|
||||||
const currentInstances = get().instances;
|
set((state) => {
|
||||||
|
const updated = state.instances.map(i =>
|
||||||
|
i.origin === origin ? { ...i, status: 'disconnected' as const, error: undefined } : i
|
||||||
|
);
|
||||||
const userId = useAuthStore.getState().user?.id;
|
const userId = useAuthStore.getState().user?.id;
|
||||||
if (userId) saveCachedTokens(currentInstances, userId);
|
if (userId) saveCachedTokens(updated, userId);
|
||||||
|
return { instances: updated, registry, registryUpdatedAt };
|
||||||
set((state) => ({
|
});
|
||||||
instances: state.instances.filter(i => i.origin !== origin),
|
|
||||||
registry,
|
|
||||||
registryUpdatedAt,
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Remove spaces from this instance from the space store
|
// Remove spaces from this instance from the space store
|
||||||
useSpaceStore.getState().removeInstanceSpaces(origin);
|
useSpaceStore.getState().removeInstanceSpaces(origin);
|
||||||
|
|||||||
Reference in New Issue
Block a user