Bachelorthesis_Code/frontend/src/components/pages/Secret.jsx

26 lines
624 B
React
Raw Normal View History

import { useEffect, useState } from "react";
2021-06-23 01:40:37 +00:00
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>;
}
2021-06-23 01:40:37 +00:00
export default Secret;