48 lines
1.3 KiB
React
Raw Normal View History

2025-07-24 11:43:01 +07:00
import { useEffect, useState } from "react";
import { toast } from "sonner";
import Container from "../Container";
import NavBar from "../NavBar";
import MyAccount from "./MyAccount";
import Register from "./Register";
function Account() {
2025-07-24 11:43:01 +07:00
const [isLoggedIn, setIsLoggedIn] = useState(null);
2025-07-22 17:45:48 +07:00
useEffect(() => {
fetch("/login/status", {
method: "POST",
2025-07-24 11:43:01 +07:00
credentials: "include",
2025-07-22 17:45:48 +07:00
})
.then((res) => res.json())
.then((data) => {
if (data.message === "True") {
setIsLoggedIn(true);
} else {
setIsLoggedIn(false);
}
})
.catch((err) => {
2025-07-24 11:43:01 +07:00
toast.error(`Error checking login status. Reason: ${err.message}`);
2025-07-22 17:45:48 +07:00
console.error("Error checking login status:", err);
2025-07-24 11:43:01 +07:00
setIsLoggedIn(false);
2025-07-22 17:45:48 +07:00
});
}, []);
2025-07-22 17:45:48 +07:00
if (isLoggedIn === null) {
2025-07-24 11:43:01 +07:00
return <div>Loading...</div>;
2025-07-22 17:45:48 +07:00
}
2025-07-22 17:45:48 +07:00
return (
2025-07-24 11:43:01 +07:00
<>
<NavBar />
<Container>
<div id="accountpage" className="flex h-full w-full">
{isLoggedIn ? <MyAccount /> : <Register />}
</div>
</Container>
</>
2025-07-22 17:45:48 +07:00
);
}
export default Account;