// src/pages/Auth/LoginForm.jsx // Bejelentkezési űrlap import InputBox from "../../components/Inputs/InputBox" import Button from "../../components/Buttons/Button" import { motion } from "framer-motion" import { useState, useEffect } from "react" import { useLocation, useNavigate } from "react-router-dom" import { login } from "../../api/userApi" export default function LoginForm() { const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [error, setError] = useState("") const location = useLocation() const navigate = useNavigate() const [showSuccess, setShowSuccess] = useState(false) const [showErrorPopup, setShowErrorPopup] = useState(false) useEffect(() => { if (location.state && location.state.success) { setShowSuccess(true) setTimeout(() => setShowSuccess(false), 4000) } }, [location.state]) function validateEmail(email) { return /\S+@\S+\.\S+/.test(email) } const handleSubmit = (e) => { e.preventDefault() setError("") setShowErrorPopup(false) if (!email || !password) { setError("Minden mező kitöltése kötelező.") setShowErrorPopup(true) setTimeout(() => setShowErrorPopup(false), 2000) return } if (!validateEmail(email)) { setError("Hibás email formátum.") setShowErrorPopup(true) setTimeout(() => setShowErrorPopup(false), 2000) return } // Backend API login(email, password) .then((response) => { console.log(response) // Csak a response.status-t ellenőrizd! if (response && response.status === 200) { if (response.data && response.data.user) { localStorage.setItem("username", response.data.user.username) localStorage.setItem("authLevel", response.data.user.authLevel) } navigate("/home") } else { setError("Hibás bejelentkezési adatok.") setShowErrorPopup(true) setTimeout(() => setShowErrorPopup(false), 2000) } }) .catch((error) => { setError("Hibás bejelentkezési adatok.") setShowErrorPopup(true) setTimeout(() => setShowErrorPopup(false), 2000) }) } return (

Bejelentkezés

{showSuccess && (
Sikeres regisztráció! Az email ellenőrzése után be tudsz lépni.
)} {showErrorPopup && error && (
{error}
)}
setEmail(e.target.value)} /> setPassword(e.target.value)} />