fix(web): reauthenticateInstance works without existing live instance (stale disconnected entries)

This commit is contained in:
Jannis Braun
2026-04-02 08:50:35 +02:00
parent 7a3945e2f1
commit cc90b5fa65
+10 -9
View File
@@ -564,25 +564,26 @@ export const useInstanceStore = create<InstanceState>((set, get) => ({
reauthenticateInstance: async (origin: string, password: string) => { reauthenticateInstance: async (origin: string, password: string) => {
const inst = get().instances.find(i => i.origin === origin); const inst = get().instances.find(i => i.origin === origin);
if (!inst) return;
// Remove the stale placeholder // Clean up existing instance if present (stale placeholder or disconnected entry)
set((state) => ({ if (inst) {
instances: state.instances.filter(i => i.origin !== origin), set((state) => ({
})); instances: state.instances.filter(i => i.origin !== origin),
}));
// Remove its spaces from the space store useSpaceStore.getState().removeInstanceSpaces(origin);
useSpaceStore.getState().removeInstanceSpaces(origin); }
// Disconnect any lingering WS // Disconnect any lingering WS
disconnectWs(origin); disconnectWs(origin);
// Re-connect through the standard flow (handles register/login) // Re-connect through the standard flow (handles register/login)
const currentUser = useAuthStore.getState().user; const currentUser = useAuthStore.getState().user;
if (!currentUser) return;
await get().connectToRemote( await get().connectToRemote(
origin, origin,
password, password,
currentUser?.displayName || undefined, currentUser.displayName || undefined,
); );
// Clear pending password sync — connectToRemote uses the current password // Clear pending password sync — connectToRemote uses the current password