Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions apps/twig/src/renderer/features/auth/stores/authStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PostHogAPIClient } from "@api/posthogClient";
import { resetSessionService } from "@features/sessions/service/service";
import { identifyUser, resetUser, track } from "@renderer/lib/analytics";
import { electronStorage } from "@renderer/lib/electronStorage";
import { logger } from "@renderer/lib/logger";
Expand All @@ -21,6 +20,12 @@ const log = logger.scope("auth-store");
let refreshPromise: Promise<void> | null = null;
let initializePromise: Promise<boolean> | null = null;

let sessionResetCallback: (() => void) | null = null;

export function setSessionResetCallback(callback: () => void) {
sessionResetCallback = callback;
}

const REFRESH_MAX_RETRIES = 3;
const REFRESH_INITIAL_DELAY_MS = 1000;

Expand Down Expand Up @@ -644,7 +649,7 @@ export const useAuthStore = create<AuthState>()(
}

// Clean up all existing sessions before switching projects
resetSessionService();
sessionResetCallback?.();

const apiHost = getCloudUrlFromRegion(cloudRegion);

Expand Down Expand Up @@ -706,7 +711,7 @@ export const useAuthStore = create<AuthState>()(
resetUser();

// Clean up session service subscriptions before clearing auth state
resetSessionService();
sessionResetCallback?.();

trpcVanilla.analytics.resetUser.mutate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const mockAuthStore = vi.hoisted(() => ({
},
})),
},
setSessionResetCallback: vi.fn(),
}));

vi.mock("@features/auth/stores/authStore", () => mockAuthStore);
Expand Down
7 changes: 6 additions & 1 deletion apps/twig/src/renderer/features/sessions/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import type {
RequestPermissionRequest,
SessionConfigOption,
} from "@agentclientprotocol/sdk";
import { useAuthStore } from "@features/auth/stores/authStore";
import {
setSessionResetCallback,
useAuthStore,
} from "@features/auth/stores/authStore";
import { useModelsStore } from "@features/sessions/stores/modelsStore";
import { useSessionAdapterStore } from "@features/sessions/stores/sessionAdapterStore";
import {
Expand Down Expand Up @@ -89,6 +92,8 @@ export function resetSessionService(): void {
});
}

setSessionResetCallback(resetSessionService);

export class SessionService {
private connectingTasks = new Map<string, Promise<void>>();
private subscriptions = new Map<
Expand Down
Loading