import React, { useEffect, useState } from "react"; import Register from "./Register"; import MyAccount from "./MyAccount"; // <-- Import the MyAccount component function Account() { const [isLoggedIn, setIsLoggedIn] = useState(null); // null = loading state useEffect(() => { fetch("/login/status", { method: "POST", credentials: "include", // Sends cookies with request }) .then((res) => res.json()) .then((data) => { if (data.message === "True") { setIsLoggedIn(true); } else { setIsLoggedIn(false); } }) .catch((err) => { console.error("Error checking login status:", err); setIsLoggedIn(false); // Assume not logged in on error }); }, []); if (isLoggedIn === null) { return
Loading...
; // Optional loading UI } return (
{isLoggedIn ? : }
); } export default Account;