// app/portal/account/AccountClient.tsx "use client"; import { useEffect, useState } from "react"; import Link from "next/link"; type Me = { id: string; username: string; first_name?: string | null; last_name?: string | null; email?: string | null; location?: string | null; avatar?: { id: string; filename_download?: string } | null; }; export default function AccountClient() { const [me, setMe] = useState(null); const [loading, setLoading] = useState(true); const [needReauth, setNeedReauth] = useState(false); const [error, setError] = useState(null); async function load() { setLoading(true); setError(null); setNeedReauth(false); try { const res = await fetch("/api/account", { credentials: "include", cache: "no-store", }); if (res.status === 401 || res.status === 403) { setNeedReauth(true); setMe(null); return; } if (!res.ok) { const j = await res.json().catch(() => ({})); throw new Error(j?.error || `Failed: ${res.status}`); } const j = await res.json(); setMe(j as Me); } catch (e: any) { setError(e?.message || "Failed to load account"); } finally { setLoading(false); } } useEffect(() => { load(); }, []); if (loading) { return
Loading account…
; } if (needReauth) { return (

Confirm it’s you

For security, please sign in again before changing account details.

Re-authenticate
); } if (error) { return (
Error: {error}
); } if (!me) return null; return (
{/* View-only header */}

Account

Username: {me.username}{" "} (usernames can’t be changed)

{/* Your existing edit forms can sit here, wired to: - PATCH /api/account for first_name, last_name, email (optional), location - POST /api/account/password for password change (asks current password in the form) - POST /api/account/avatar for avatar upload (to your folder) None of these fire automatically; only on submit. */} {/* Example placeholder showing current profile fields */}

Profile

First name: {me.first_name || "—"}
Last name: {me.last_name || "—"}
Email: {me.email || "—"}
Location: {me.location || "—"}
); }