2025-04-30 03:42:38 -04:00
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
import Register from "./Register";
|
|
|
|
import MyAccount from "./MyAccount"; // <-- Import the MyAccount component
|
|
|
|
|
|
|
|
function Account() {
|
2025-07-22 17:45:48 +07:00
|
|
|
const [isLoggedIn, setIsLoggedIn] = useState(null); // null = loading state
|
2025-04-30 03:42:38 -04:00
|
|
|
|
2025-07-22 17:45:48 +07:00
|
|
|
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
|
|
|
|
});
|
|
|
|
}, []);
|
2025-04-30 03:42:38 -04:00
|
|
|
|
2025-07-22 17:45:48 +07:00
|
|
|
if (isLoggedIn === null) {
|
|
|
|
return <div>Loading...</div>; // Optional loading UI
|
|
|
|
}
|
2025-04-30 03:42:38 -04:00
|
|
|
|
2025-07-22 17:45:48 +07:00
|
|
|
return (
|
|
|
|
<div id="accountpage" className="w-full h-full flex">
|
|
|
|
{isLoggedIn ? <MyAccount /> : <Register />}
|
|
|
|
</div>
|
|
|
|
);
|
2025-04-30 03:42:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Account;
|