This commit is contained in:
eric
2026-03-12 03:54:22 -05:00
parent 421f979e10
commit e7dde61e31
23 changed files with 876 additions and 125 deletions

View File

@@ -25,11 +25,28 @@ export default function Header() {
const [userEmail, setUserEmail] = useState<string | null>(null);
useEffect(() => {
setUserEmail(getStoredUserEmail());
let mounted = true;
(async () => {
try {
const res = await fetch("/api/auth/me");
const data = await res.json();
if (!mounted) return;
if (data?.user && data?.token) {
const { pbSaveAuth } = await import("@/app/lib/pocketbase");
pbSaveAuth(data.token, { id: data.user.id, email: data.user.email });
setUserEmail(data.user.email);
return;
}
} catch {
/* ignore */
}
if (mounted) setUserEmail(getStoredUserEmail());
})();
return () => { mounted = false; };
}, []);
const handleLogout = () => {
pbLogout();
const handleLogout = async () => {
await pbLogout();
setUserEmail(null);
};