From 00173bdb7e78f5a8d2c35620c90b3e5a18a645bf Mon Sep 17 00:00:00 2001 From: CTO Agent Date: Tue, 7 Apr 2026 14:09:30 +0000 Subject: [PATCH] fix: wire account override to /files page sandbox API calls Uses useAccountOverride() in sandbox hooks to pass the resolved accountIdOverride as account_id query param to the API. This ensures the /files page shows the overridden account's files when using the email query param override. Co-Authored-By: Paperclip --- hooks/useSandboxFileContent.ts | 4 +++- hooks/useSandboxes.ts | 6 ++++-- lib/sandboxes/getFileContents.ts | 20 ++++++++++++-------- lib/sandboxes/getSandboxes.ts | 10 ++++++++-- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/hooks/useSandboxFileContent.ts b/hooks/useSandboxFileContent.ts index 7835ea88b..654b60e78 100644 --- a/hooks/useSandboxFileContent.ts +++ b/hooks/useSandboxFileContent.ts @@ -2,6 +2,7 @@ import { useCallback, useState } from "react"; import { useMutation } from "@tanstack/react-query"; import { usePrivy } from "@privy-io/react-auth"; import { getFileContents } from "@/lib/sandboxes/getFileContents"; +import { useAccountOverride } from "@/providers/AccountOverrideProvider"; interface UseSandboxFileContentReturn { selectedPath: string | undefined; @@ -14,6 +15,7 @@ interface UseSandboxFileContentReturn { export default function useSandboxFileContent(): UseSandboxFileContentReturn { const { getAccessToken } = usePrivy(); + const { accountIdOverride } = useAccountOverride(); const [selectedPath, setSelectedPath] = useState(); const mutation = useMutation({ @@ -23,7 +25,7 @@ export default function useSandboxFileContent(): UseSandboxFileContentReturn { throw new Error("Please sign in to view file contents"); } - return getFileContents(accessToken, path); + return getFileContents(accessToken, path, accountIdOverride); }, }); diff --git a/hooks/useSandboxes.ts b/hooks/useSandboxes.ts index 0deff6d7f..5b287513d 100644 --- a/hooks/useSandboxes.ts +++ b/hooks/useSandboxes.ts @@ -4,6 +4,7 @@ import { usePrivy } from "@privy-io/react-auth"; import { getSandboxes } from "@/lib/sandboxes/getSandboxes"; import { convertFileTreeEntries } from "@/lib/sandboxes/convertFileTreeEntries"; import getSubtreeAtPath from "@/lib/sandboxes/getSubtreeAtPath"; +import { useAccountOverride } from "@/providers/AccountOverrideProvider"; import type { Sandbox } from "@/lib/sandboxes/createSandbox"; import type { FileNode } from "@/lib/sandboxes/parseFileTree"; @@ -17,15 +18,16 @@ interface UseSandboxesReturn { export default function useSandboxes(): UseSandboxesReturn { const { getAccessToken, authenticated } = usePrivy(); + const { accountIdOverride } = useAccountOverride(); const query = useQuery({ - queryKey: ["sandboxes"], + queryKey: ["sandboxes", accountIdOverride], queryFn: async () => { const accessToken = await getAccessToken(); if (!accessToken) { throw new Error("Please sign in to view sandboxes"); } - return getSandboxes(accessToken); + return getSandboxes(accessToken, accountIdOverride); }, enabled: authenticated, }); diff --git a/lib/sandboxes/getFileContents.ts b/lib/sandboxes/getFileContents.ts index 47472b71b..7b33318ba 100644 --- a/lib/sandboxes/getFileContents.ts +++ b/lib/sandboxes/getFileContents.ts @@ -21,16 +21,20 @@ interface FileContentsResult { export async function getFileContents( accessToken: string, path: string, + accountId?: string | null, ): Promise { - const response = await fetch( - `${getClientApiBaseUrl()}/api/sandboxes/file?path=${encodeURIComponent(path)}`, - { - method: "GET", - headers: { - Authorization: `Bearer ${accessToken}`, - }, + const url = new URL(`${getClientApiBaseUrl()}/api/sandboxes/file`); + url.searchParams.set("path", path); + if (accountId) { + url.searchParams.set("account_id", accountId); + } + + const response = await fetch(url.toString(), { + method: "GET", + headers: { + Authorization: `Bearer ${accessToken}`, }, - ); + }); const data: GetFileContentsResponse = await response.json(); diff --git a/lib/sandboxes/getSandboxes.ts b/lib/sandboxes/getSandboxes.ts index d5b776d4d..3e57ad228 100644 --- a/lib/sandboxes/getSandboxes.ts +++ b/lib/sandboxes/getSandboxes.ts @@ -15,9 +15,15 @@ export interface GetSandboxesResult { } export async function getSandboxes( - accessToken: string + accessToken: string, + accountId?: string | null, ): Promise { - const response = await fetch(`${getClientApiBaseUrl()}/api/sandboxes`, { + const url = new URL(`${getClientApiBaseUrl()}/api/sandboxes`); + if (accountId) { + url.searchParams.set("account_id", accountId); + } + + const response = await fetch(url.toString(), { method: "GET", headers: { Authorization: `Bearer ${accessToken}`,