Enrollment + almost all auth

This commit is contained in:
mdares
2026-01-03 20:18:39 +00:00
parent 0ad2451dd4
commit a0ed517047
40 changed files with 3559 additions and 31 deletions

View File

@@ -2,6 +2,7 @@
import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import { useEffect, useState } from "react";
const items = [
{ href: "/overview", label: "Overview", icon: "🏠" },
@@ -13,6 +14,30 @@ const items = [
export function Sidebar() {
const pathname = usePathname();
const router = useRouter();
const [me, setMe] = useState<{
user?: { name?: string | null; email?: string | null };
org?: { name?: string | null };
membership?: { role?: string | null };
} | null>(null);
useEffect(() => {
let alive = true;
async function loadMe() {
try {
const res = await fetch("/api/me", { cache: "no-store" });
const data = await res.json().catch(() => ({}));
if (alive && res.ok && data?.ok) {
setMe(data);
}
} catch {
if (alive) setMe(null);
}
}
loadMe();
return () => {
alive = false;
};
}, []);
async function onLogout() {
await fetch("/api/logout", { method: "POST" });
@@ -50,8 +75,10 @@ export function Sidebar() {
<div className="px-5 py-4 border-t border-white/10 space-y-3">
<div>
<div className="text-sm text-white">Juan Pérez</div>
<div className="text-xs text-zinc-500">Plant Manager</div>
<div className="text-sm text-white">{me?.user?.name || me?.user?.email || "User"}</div>
<div className="text-xs text-zinc-500">
{me?.org?.name ? `${me.org.name} - ${me?.membership?.role || "MEMBER"}` : "Loading..."}
</div>
</div>
<button