Skip to content

Commit 7930257

Browse files
authored
fix: ensure "Authorization" header is included when fetching a single result. (#85)
1 parent d2f8e7f commit 7930257

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/app/results/page.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,40 @@ import {
1313
} from "@chakra-ui/react";
1414
import { ChevronLeftIcon } from "@chakra-ui/icons";
1515

16-
import { STATIC } from "../../../static";
16+
import { STATIC, withFeature } from "../../../static";
1717

1818
import Result from "../../components/Result";
1919
import { search } from "@globus/sdk";
2020

2121
import type { GMetaResult } from "@/globus/search";
22+
import { useGlobusAuth } from "@/globus/globus-auth-context/useGlobusAuth";
2223

2324
const ClientSideResult = () => {
2425
const params = useSearchParams();
26+
const auth = useGlobusAuth();
2527
const subject = params.get("subject");
2628
const [result, setResult] = useState<GMetaResult>();
2729
useEffect(() => {
2830
async function fetchResult() {
31+
const headers = withFeature("authentication", () => {
32+
if (!auth.isAuthenticated || !auth.authorization?.tokens.search) {
33+
return;
34+
}
35+
return {
36+
Authorization: `Bearer ${auth.authorization.tokens.search.access_token}`,
37+
};
38+
});
39+
2940
const response = await (
3041
await search.subject.get(STATIC.data.attributes.globus.search.index, {
3142
query: {
3243
subject: Array.isArray(subject) ? subject[0] : subject,
3344
},
45+
headers: headers ?? undefined,
3446
})
3547
).json();
3648
setResult(response);
3749
}
38-
3950
fetchResult();
4051
}, [subject]);
4152
return <Result result={result} />;

0 commit comments

Comments
 (0)