Skip to content

Commit 975c55a

Browse files
committed
example: Initialise example with auth
1 parent 575da0f commit 975c55a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

example/src/pages/Main/QueryBuilder.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ function QueryBuilder ({
2323

2424
const handleRangeFromChange = useCallback((e) => setDateRangeFrom(e.target.value), [setDateRangeFrom]);
2525
const handleRangeToChange = useCallback((e) => setDateRangeTo(e.target.value), [setDateRangeTo]);
26+
27+
const headers = useMemo(() => ({
28+
Authorization: "Basic " + btoa(process.env.REACT_APP_STAC_API_TOKEN + ":")
29+
}), []);
2630

27-
const stacApi = useMemo(() => new StacApi(process.env.REACT_APP_STAC_API), []);
31+
const stacApi = useMemo(() => new StacApi(process.env.REACT_APP_STAC_API, { headers }), [headers]);
2832
const { collections } = useCollections(stacApi);
2933

3034
const collectionOptions = useMemo(

example/src/pages/Main/index.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useState } from "react";
1+
import { useCallback, useState, useMemo } from "react";
22
import { useStacSearch, StacApi } from "stac-react";
33

44
import ItemList from "./ItemList";
@@ -7,7 +7,11 @@ import QueryBuilder from "./QueryBuilder";
77

88
function Main() {
99
const [isBboxDrawEnabled, setIsBboxDrawEnabled] = useState(false);
10-
const stacApi = new StacApi(process.env.REACT_APP_STAC_API);
10+
const headers = useMemo(() => ({
11+
Authorization: "Basic " + btoa(process.env.REACT_APP_STAC_API_TOKEN + ":")
12+
}), []);
13+
14+
const stacApi = new StacApi(process.env.REACT_APP_STAC_API, { headers });
1115
const {
1216
setBbox,
1317
collections,

0 commit comments

Comments
 (0)