'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { Lock, User, Key, ArrowRight, ShieldCheck, Loader2 } from 'lucide-react'; import Link from 'next/link'; export default function LoginPage() { const router = useRouter(); const [step, setStep] = useState<'credentials' | 'otp'>('credentials'); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [formData, setFormData] = useState({ username: '', password: '', otp: '' }); const handleLogin = 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({ username: formData.username, password: formData.password }) }); const data = await res.json(); if (!res.ok) throw new Error(data.error || 'Error al iniciar sesión'); if (data.requireOtp) { setStep('otp'); } else { router.push('/'); router.refresh(); } } catch (err: any) { setError(err.message); } finally { setLoading(false); } }; const handleVerifyOtp = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); try { const res = await fetch('/api/auth/verify-otp', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: formData.username, otp: formData.otp }) }); const data = await res.json(); if (!res.ok) throw new Error(data.error || 'Código incorrecto'); router.push('/'); router.refresh(); } catch (err: any) { setError(err.message); } finally { setLoading(false); } }; return (
{/* Header */}

Bienvenido

Sistema de Finanzas Personales

{error && (
{error}
)} {step === 'credentials' ? (
setFormData({...formData, username: e.target.value})} className="w-full pl-10 pr-4 py-2.5 bg-slate-950 border border-slate-800 rounded-lg text-white focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500 outline-none transition-all placeholder:text-slate-600" placeholder="Ingresa tu usuario" />
setFormData({...formData, password: e.target.value})} className="w-full pl-10 pr-4 py-2.5 bg-slate-950 border border-slate-800 rounded-lg text-white focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500 outline-none transition-all placeholder:text-slate-600" placeholder="••••••••" />
) : (

Verificación de Identidad

Hemos enviado un código a tu Telegram.
Ingrésalo para continuar.

setFormData({...formData, otp: e.target.value.replace(/\D/g, '')})} className="w-full text-center text-2xl tracking-[0.5em] font-mono py-3 bg-slate-950 border border-slate-800 rounded-lg text-white focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none transition-all" placeholder="000000" />
)}

¿No tienes cuenta?{' '} Regístrate aquí

); }