import { useEffect, useState } from "react/cjs/react.development";
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;
