Skip to content

Commit

Permalink
added auth to single record fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Unit committed Feb 13, 2025
1 parent 9da8aca commit 64b0a44
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions apps/supercatalog/src/pages/record/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Chip, CircularProgress, Container } from "@mui/material";
import { getCurrentEndpoint, type Result } from "@dans-framework/rdt-search-ui";
import { getCurrentEndpoint, type Result, type EndpointProps } from "@dans-framework/rdt-search-ui";
import { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import Button from "@mui/material/Button";
Expand All @@ -10,6 +10,7 @@ import Grid from "@mui/material/Unstable_Grid2";
import { motion } from "framer-motion";
import CloseIcon from '@mui/icons-material/Close';
import IconButton from '@mui/material/IconButton';
import { elasticConfig } from "../../config/elasticSearch";

interface SingleRecord {
id: string;
Expand Down Expand Up @@ -104,8 +105,19 @@ export function SingleRecord({ onClose }: { onClose: () => void }) {
const [loading, setLoading] = useState(true);

useEffect(() => {
const currentEndpointConfig: EndpointProps | undefined = elasticConfig.find((config) => config.url === endpoint);
if (id) {
fetch(`${endpoint}/_source/${encodeURIComponent(id)}`)
fetch(
`${endpoint}/_source/${encodeURIComponent(id)}`, {
headers: {
"Content-Type": "application/json",
// if user and pass are provided, add basic auth header
...(currentEndpointConfig?.user && currentEndpointConfig?.pass && {
Authorization: `Basic ${btoa(`${currentEndpointConfig.user}:${currentEndpointConfig.pass}`)}`,
}),
},
}
)
.then((res) => {
setLoading(false);
if (!res.ok) {
Expand Down

0 comments on commit 64b0a44

Please sign in to comment.