mirror of
https://github.com/apricote/Listory.git
synced 2026-02-06 17:57:03 +00:00
feat(frontend): setup
This commit is contained in:
parent
db62d5d908
commit
f14eda16ac
33 changed files with 15076 additions and 22 deletions
37
frontend/src/views/ExternalApi.js
Normal file
37
frontend/src/views/ExternalApi.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue