"use client"; import React, { useState } from "react"; import { signInWithEmailAndPassword } from "firebase/auth"; import { auth } from "@/lib/firebase"; import { useRouter } from "next/navigation"; import { motion } from "framer-motion"; import { Lock, User, ArrowRight, ShieldCheck } from "lucide-react"; import Link from "next/link"; export default function LoginPage() { const [email, setEmail] = useState("admin@erp.com"); const [password, setPassword] = useState("admin123"); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const router = useRouter(); const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(""); try { await signInWithEmailAndPassword(auth, email, password); router.push("/"); } catch (err: any) { // Auto-create admin if it doesn't exist if (err.code === "auth/user-not-found" && email === "admin@erp.com") { try { const { createUserWithEmailAndPassword } = await import("firebase/auth"); await createUserWithEmailAndPassword(auth, email, password); router.push("/"); return; } catch (regErr: any) { setError("Error al crear cuenta administrativa automática."); } } else if (err.code === "auth/invalid-credential" || err.code === "auth/wrong-password") { setError("Credenciales inválidas. Intente de nuevo."); } else { setError("Error de conexión. Intente de nuevo."); } setLoading(false); } }; return (
Acceso Seguro al Panel de Control
Modo Demo Activado
Haga clic en 'Entrar' para acceder rápidamente.
¿No tienes una cuenta? {" "} Regístrate aquí