From 0bc67566d7c39454a326d42d8fb3c74fec2ce9b5 Mon Sep 17 00:00:00 2001 From: Peter Kirkham Date: Wed, 29 Apr 2026 14:02:10 +0100 Subject: [PATCH] fix: use null auth store, use hook instead of zust store --- apps/code/src/renderer/features/auth/hooks/authQueries.ts | 7 +++++++ apps/code/src/renderer/utils/posthogLinks.ts | 4 ++-- apps/code/src/renderer/utils/urls.ts | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/code/src/renderer/features/auth/hooks/authQueries.ts b/apps/code/src/renderer/features/auth/hooks/authQueries.ts index 958f0b6e7..c7a7198c7 100644 --- a/apps/code/src/renderer/features/auth/hooks/authQueries.ts +++ b/apps/code/src/renderer/features/auth/hooks/authQueries.ts @@ -36,6 +36,13 @@ export async function fetchAuthState(): Promise { return await trpcClient.auth.getState.query(); } +export function getCachedAuthState(): AuthState { + return ( + queryClient.getQueryData(trpc.auth.getState.queryKey()) ?? + ANONYMOUS_AUTH_STATE + ); +} + export async function refreshAuthStateQuery(): Promise { await queryClient.invalidateQueries(trpc.auth.getState.pathFilter()); } diff --git a/apps/code/src/renderer/utils/posthogLinks.ts b/apps/code/src/renderer/utils/posthogLinks.ts index 58c7123c3..8a74b5120 100644 --- a/apps/code/src/renderer/utils/posthogLinks.ts +++ b/apps/code/src/renderer/utils/posthogLinks.ts @@ -1,4 +1,4 @@ -import { useAuthStore } from "@features/auth/stores/authStore"; +import { getCachedAuthState } from "@features/auth/hooks/authQueries"; import type { CloudRegion } from "@shared/types/regions"; import { getPostHogUrl } from "@utils/urls"; @@ -9,7 +9,7 @@ export interface LinkOverrides { function resolveProjectId(override?: number | null): number | null { if (override != null) return override; - return useAuthStore.getState().projectId ?? null; + return getCachedAuthState().projectId ?? null; } function withProjectId( diff --git a/apps/code/src/renderer/utils/urls.ts b/apps/code/src/renderer/utils/urls.ts index 5e14c7bee..deaea2581 100644 --- a/apps/code/src/renderer/utils/urls.ts +++ b/apps/code/src/renderer/utils/urls.ts @@ -1,4 +1,4 @@ -import { useAuthStore } from "@features/auth/stores/authStore"; +import { getCachedAuthState } from "@features/auth/hooks/authQueries"; import type { CloudRegion } from "@shared/types/regions"; import { getCloudUrlFromRegion } from "@shared/utils/urls"; @@ -6,7 +6,7 @@ export function getPostHogUrl( path: string, regionOverride?: CloudRegion | null, ): string | null { - const region = regionOverride ?? useAuthStore.getState().cloudRegion; + const region = regionOverride ?? getCachedAuthState().cloudRegion; if (!region) return null; const base = getCloudUrlFromRegion(region); return `${base}${path.startsWith("/") ? path : `/${path}`}`;