Bachelorthesis_Code/frontend/src/components/pages/Secret.jsx
cami 85e484bf0b
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
Renaming and autoformatting
- renamed the react files to jsx
- autoformat with vscode
2021-07-22 20:18:01 +02:00

25 lines
624 B
JavaScript

import { useEffect, useState } from "react";
import { authFetch } from "../../auth/AuthProvider.js";
function Secret() {
const [message, setMessage] = useState("");
useEffect(() => {
authFetch("/api/protected")
.then((response) => {
if (response.status === 401) {
setMessage("Sorry, du bist nicht angemeldet");
return null;
}
return response.json();
})
.then((response) => {
if (response && response.message) {
setMessage(response.message);
}
});
}, []);
return <h2>Secret: {message}</h2>;
}
export default Secret;