fix(web): load space profile from profile API (#1079)

This commit is contained in:
Vedant Mahajan 2026-06-10 13:22:44 +05:30 committed by GitHub
parent a068a794dd
commit 9ab2e7e64f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<SpaceProfile> => {
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,