diff --git a/apps/web/hooks/use-space-profile.ts b/apps/web/hooks/use-space-profile.ts index 9ee2114d..8883625f 100644 --- a/apps/web/hooks/use-space-profile.ts +++ b/apps/web/hooks/use-space-profile.ts @@ -1,5 +1,4 @@ import { useQuery } from "@tanstack/react-query" -import { $fetch } from "@lib/api" import { useAuth } from "@lib/auth-context" export type SpaceProfile = { @@ -7,6 +6,16 @@ export type SpaceProfile = { dynamic: string[] } +const API_BASE = + process.env.NEXT_PUBLIC_BACKEND_URL ?? "https://api.supermemory.ai" + +type SpaceProfileResponse = { + profile?: { + static?: string[] | null + dynamic?: string[] | null + } | null +} + export function useSpaceProfile(containerTag: string) { const { org } = useAuth() const orgId = org?.id ?? "" @@ -14,21 +23,32 @@ export function useSpaceProfile(containerTag: string) { return useQuery({ queryKey: ["space-profile", orgId, containerTag], queryFn: async (): Promise => { - const response = await $fetch( - "@get/container-tags/:containerTag/profile", - { - params: { containerTag }, + const response = await fetch(`${API_BASE}/v4/profile`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json", + "X-App-Source": "nova", }, - ) - if (response.error) { + body: JSON.stringify({ containerTag }), + }) + + if (!response.ok) { + const body = (await response.json().catch(() => ({}))) as { + error?: string + message?: string + } throw new Error( - response.error.message || "Failed to load space profile", + body.message ?? body.error ?? "Failed to load space profile", ) } - const profile = response.data.profile + + const data = (await response.json()) as SpaceProfileResponse + const profile = data.profile + return { - static: profile.static ?? [], - dynamic: profile.dynamic ?? [], + static: profile?.static ?? [], + dynamic: profile?.dynamic ?? [], } }, enabled: !!orgId && !!containerTag,