"use client" import { useState, useEffect } from "react" import { useRouter } from "next/navigation" import { Eye, EyeOff } from "lucide-react" export default function ClientLoginPage() { const router = useRouter() const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [showPassword, setShowPassword] = useState(false) const [loading, setLoading] = useState(false) const [error, setError] = useState("") const [checking, setChecking] = useState(true) useEffect(() => { fetch("/api/auth/me", { credentials: "include" }) .then((r) => r.json()) .then((data) => { if (data.role === "client") router.push("/client-portal/dashboard") else setChecking(false) }) .catch(() => setChecking(false)) }, [router]) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) setError("") try { const res = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password }), }) const data = await res.json() if (!res.ok) { setError(data.error || "Login failed") return } if (data.user?.role !== "client") { setError("This portal is for clients only") return } router.push("/client-portal/dashboard") } catch { setError("Connection error") } finally { setLoading(false) } } if (checking) { return (
) } return (
Client Portal

Sign in to view your projects and invoices

setEmail(e.target.value)} className="w-full bg-[#1a1a24] border border-[#2a2a35] rounded-lg px-3 py-2.5 text-sm text-white placeholder-[#6a6a75] outline-none focus:border-[#1BB0CE]/50" placeholder="your@email.com" required />
setPassword(e.target.value)} className="w-full bg-[#1a1a24] border border-[#2a2a35] rounded-lg px-3 py-2.5 pr-10 text-sm text-white placeholder-[#6a6a75] outline-none focus:border-[#1BB0CE]/50" placeholder="Enter password" required />
{error && (
{error}
)}
) }