"use client" import { useState, useEffect } from "react" import { signIn, useSession } from "next-auth/react" import { useRouter } from "next/navigation" import Link from "next/link" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { User, Lock, AlertCircle } from "lucide-react" import { notifications } from "@/lib/notifications" export default function LoginPage() { const [username, setUsername] = useState("") const [password, setPassword] = useState("") const [loading, setLoading] = useState(false) const router = useRouter() const { data: session, status } = useSession() // Redirigir si ya está autenticado useEffect(() => { if (session) { router.push("/dashboard") } }, [session, router]) // Mostrar loading mientras se verifica la sesión if (status === "loading") { return (
) } // Si ya está autenticado, mostrar loading mientras redirige if (session) { return (

Redirigiendo...

) } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) try { const result = await signIn("credentials", { username, password, redirect: false, }) if (result?.error) { notifications.auth.loginError() } else { notifications.auth.loginSuccess() router.push("/dashboard") } } catch (error) { console.error("Error en login:", error) notifications.auth.loginGeneralError() } finally { setLoading(false) } } return (
Ani Assistant

Inicia sesión en tu cuenta

setUsername(e.target.value)} required />
setPassword(e.target.value)} required />

Acceso UTB: Usa tus credenciales institucionales (ejemplo: 1206706838-EST)

) }