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
7 changes: 7 additions & 0 deletions apps/code/src/renderer/features/auth/hooks/authQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export async function fetchAuthState(): Promise<AuthState> {
return await trpcClient.auth.getState.query();
}

export function getCachedAuthState(): AuthState {
return (
queryClient.getQueryData<AuthState>(trpc.auth.getState.queryKey()) ??
ANONYMOUS_AUTH_STATE
);
}

export async function refreshAuthStateQuery(): Promise<void> {
await queryClient.invalidateQueries(trpc.auth.getState.pathFilter());
}
Expand Down
4 changes: 2 additions & 2 deletions apps/code/src/renderer/utils/posthogLinks.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions apps/code/src/renderer/utils/urls.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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";

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}`}`;
Expand Down
Loading