"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useAuth } from "@/components/auth/auth-provider";
import { ProfileForm } from "./profile-form";
/**
* /profile is a client-rendered page guarded by useAuth.
*
* We deliberately do NOT use Next.js middleware for the auth gate: the
* session cookie is httpOnly on the BFF domain, and middleware-level
* cookie forwarding to the BFF is more code than this approach is worth.
*
* Instead the page renders a loading state until AuthProvider hydrates,
* then either shows the form or redirects to /login.
*/
export default function ProfilePage() {
const router = useRouter();
const { user, loading } = useAuth();
useEffect(() => {
if (!loading && !user) {
router.replace("/login?next=/profile");
}
}, [loading, user, router]);
if (loading || !user) {
return (