"use client"; import Link from "next/link"; import { useEffect, useState } from "react"; import { browserFetch } from "../lib/api"; import { logoutByNavigation } from "../lib/logout"; type MeResponse = { user: { id: string; email: string; role: string } | null; makerProfile: { id: string; slug: string; business_name: string | null; status: string } | null; }; export default function ProfileClient() { const [session, setSession] = useState(null); const [loading, setLoading] = useState(true); const [status, setStatus] = useState(""); useEffect(() => { let active = true; async function loadSession() { try { const response = await browserFetch("/auth/me"); if (active) { setSession(response); } } catch (error) { if (active) { setStatus(error instanceof Error ? error.message : "No se pudo cargar la sesion"); setSession({ user: null, makerProfile: null }); } } finally { if (active) { setLoading(false); } } } void loadSession(); return () => { active = false; }; }, []); useEffect(() => { if (session?.user?.role === "admin") { window.location.replace("/app/backoffice"); } }, [session?.user?.role]); function logout() { logoutByNavigation(); } if (loading) { return (

Cargando perfil

Validando tu sesion para mostrar el acceso correcto.

); } if (!session?.user) { return (

Necesitas iniciar sesion

Entra con un usuario demo para probar cliente, maker o administrador.

Entrar
); } if (session.user.role === "admin") { return (
Backoffice

Redirigiendo al panel administrador

La cuenta superadmin no usa perfil maker ni perfil cliente.

{status ?

{status}

: null}
); } if (session.makerProfile && session.makerProfile.status !== "draft") { const makerName = session.makerProfile.business_name || "Tu espacio Maker"; return (
{makerName.slice(0, 2).toUpperCase()}
Perfil maker

{makerName}

{session.user.email}

ActivoEstado de cuenta
{session.makerProfile.status}Perfil publico
Mi espacio maker Dashboard, trabajos, servicios y reputacion. Consultas recibidas Mensajes de clientes y propuestas de trabajo. Ver perfil publico Asi te ven clientes y proveedores. Favoritos Makers y trabajos que guardaste.
{status ?

{status}

: null}
); } return (
CL
Perfil cliente

Tu cuenta de cliente

{session.user.email}

Mensajes Tus consultas enviadas a makers y sus respuestas. Favoritos Makers y trabajos guardados para revisar despues. Crear mi espacio maker Solo si tambien queres publicar servicios como maker.
{status ?

{status}

: null}
); }