'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import Image from 'next/image'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'; import { login } from '@/lib/api/auth'; import { useAuthStore } from '@/stores/auth-store'; export default function LoginPage() { const router = useRouter(); const { setUser, setTokens } = useAuthStore(); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setIsLoading(true); setError(''); const formData = new FormData(e.currentTarget); const email = formData.get('email') as string; const password = formData.get('password') as string; try { const response = await login({ email, password }); setTokens(response.accessToken, response.refreshToken); setUser(response.user); const STORAGE_KEY = 'horux360:onboarding_seen_v1'; const seen = typeof window !== 'undefined' && localStorage.getItem(STORAGE_KEY) === '1'; router.push(seen ? '/dashboard' : '/onboarding'); } catch (err: any) { setError(err.response?.data?.message || 'Error al iniciar sesión'); } finally { setIsLoading(false); } } return (
Horux360
Iniciar Sesión Ingresa tus credenciales para acceder a tu cuenta
{error && (
{error}
)}

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

); }