Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure "Authorization" header is included when fetching a single result. #85

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/app/results/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<GMetaResult>();
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 <Result result={result} />;
Expand Down