From 03ffe7f0ab0a757ee70c9771f1844610b27593c7 Mon Sep 17 00:00:00 2001 From: Joe Bottigliero <694253+jbottigliero@users.noreply.github.com> Date: Wed, 22 May 2024 12:32:31 -0500 Subject: [PATCH] fix: ensure "Authorization" header is included when fetching a single result. --- src/app/results/page.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/results/page.tsx b/src/app/results/page.tsx index 95e640e..c2ca355 100644 --- a/src/app/results/page.tsx +++ b/src/app/results/page.tsx @@ -13,29 +13,40 @@ import { } from "@chakra-ui/react"; import { ChevronLeftIcon } from "@chakra-ui/icons"; -import { STATIC } from "../../../static"; +import { STATIC, withFeature } from "../../../static"; import Result from "../../components/Result"; import { search } from "@globus/sdk"; import type { GMetaResult } from "@/globus/search"; +import { useGlobusAuth } from "@/globus/globus-auth-context/useGlobusAuth"; const ClientSideResult = () => { const params = useSearchParams(); + const auth = useGlobusAuth(); const subject = params.get("subject"); const [result, setResult] = useState(); useEffect(() => { async function fetchResult() { + const headers = withFeature("authentication", () => { + if (!auth.isAuthenticated || !auth.authorization?.tokens.search) { + return; + } + return { + Authorization: `Bearer ${auth.authorization.tokens.search.access_token}`, + }; + }); + const response = await ( await search.subject.get(STATIC.data.attributes.globus.search.index, { query: { subject: Array.isArray(subject) ? subject[0] : subject, }, + headers: headers ?? undefined, }) ).json(); setResult(response); } - fetchResult(); }, [subject]); return ;