diff --git a/app/[workspace]/projects/page.tsx b/app/[workspace]/projects/page.tsx index 355fd87b..cf4bbc40 100644 --- a/app/[workspace]/projects/page.tsx +++ b/app/[workspace]/projects/page.tsx @@ -73,6 +73,7 @@ export default function ProjectsPage() { const [projects, setProjects] = useState([]); const [loading, setLoading] = useState(true); + const [loadError, setLoadError] = useState(null); const [showNew, setShowNew] = useState(false); const [projectToDelete, setProjectToDelete] = useState(null); const [isDeleting, setIsDeleting] = useState(false); @@ -81,12 +82,20 @@ export default function ProjectsPage() { const fetchProjects = async () => { try { setLoading(true); - const res = await fetch("/api/projects"); - if (!res.ok) throw new Error("Failed to fetch projects"); + setLoadError(null); + const res = await fetch("/api/projects", { credentials: "include" }); + if (res.status === 401) { + throw new Error("Your session expired — please log in again."); + } + if (!res.ok) { + let body: { error?: string; details?: string } = {}; + try { body = await res.json(); } catch { /* keep {} */ } + throw new Error(body.error || `HTTP ${res.status} ${res.statusText}`.trim()); + } const data = await res.json(); setProjects(data.projects ?? []); - } catch { - /* silent */ + } catch (err) { + setLoadError(err instanceof Error ? err.message : "Failed to load projects"); } finally { setLoading(false); } @@ -174,6 +183,29 @@ export default function ProjectsPage() { )} + {/* Error */} + {!loading && loadError && ( +
+ {loadError} + +
+ )} + {/* Project list */} {!loading && (