mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
37 lines
889 B
JavaScript
37 lines
889 B
JavaScript
import React, { useState } from "react";
|
|
import { useAuth0 } from "../react-auth0-spa";
|
|
|
|
const ExternalApi = () => {
|
|
const [showResult, setShowResult] = useState(false);
|
|
const [apiMessage, setApiMessage] = useState("");
|
|
const { getTokenSilently } = useAuth0();
|
|
|
|
const callApi = async () => {
|
|
try {
|
|
const token = await getTokenSilently();
|
|
|
|
const response = await fetch("/api/v1/connections", {
|
|
headers: {
|
|
Authorization: `Bearer ${token}`
|
|
}
|
|
});
|
|
|
|
const responseData = await response.json();
|
|
|
|
setShowResult(true);
|
|
setApiMessage(responseData);
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<h1>External API</h1>
|
|
<button onClick={callApi}>Ping API</button>
|
|
{showResult && <code>{JSON.stringify(apiMessage, null, 2)}</code>}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default ExternalApi;
|