25 lines
624 B
JavaScript
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;
|