@@ -13,29 +13,40 @@ import {
13
13
} from "@chakra-ui/react" ;
14
14
import { ChevronLeftIcon } from "@chakra-ui/icons" ;
15
15
16
- import { STATIC } from "../../../static" ;
16
+ import { STATIC , withFeature } from "../../../static" ;
17
17
18
18
import Result from "../../components/Result" ;
19
19
import { search } from "@globus/sdk" ;
20
20
21
21
import type { GMetaResult } from "@/globus/search" ;
22
+ import { useGlobusAuth } from "@/globus/globus-auth-context/useGlobusAuth" ;
22
23
23
24
const ClientSideResult = ( ) => {
24
25
const params = useSearchParams ( ) ;
26
+ const auth = useGlobusAuth ( ) ;
25
27
const subject = params . get ( "subject" ) ;
26
28
const [ result , setResult ] = useState < GMetaResult > ( ) ;
27
29
useEffect ( ( ) => {
28
30
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
+
29
40
const response = await (
30
41
await search . subject . get ( STATIC . data . attributes . globus . search . index , {
31
42
query : {
32
43
subject : Array . isArray ( subject ) ? subject [ 0 ] : subject ,
33
44
} ,
45
+ headers : headers ?? undefined ,
34
46
} )
35
47
) . json ( ) ;
36
48
setResult ( response ) ;
37
49
}
38
-
39
50
fetchResult ( ) ;
40
51
} , [ subject ] ) ;
41
52
return < Result result = { result } /> ;
0 commit comments