From 9ab675012d3d5dc7fe467e4de23c2f8495cd89de Mon Sep 17 00:00:00 2001 From: Jose Date: Sun, 15 Feb 2026 02:19:41 +0100 Subject: [PATCH] Fix: some css and useEffects. Add: clearError on AuthContext. --- src/components/Auth/LoginForm.jsx | 4 +- src/components/Auth/RegisterForm.jsx | 61 +++++++++++++++++++++++++--- src/context/AuthContext.jsx | 3 ++ src/pages/Accounts.jsx | 8 +++- src/pages/Register.jsx | 8 +++- 5 files changed, 74 insertions(+), 10 deletions(-) diff --git a/src/components/Auth/LoginForm.jsx b/src/components/Auth/LoginForm.jsx index 7f37850..9180174 100644 --- a/src/components/Auth/LoginForm.jsx +++ b/src/components/Auth/LoginForm.jsx @@ -16,7 +16,7 @@ import '@/css/LoginForm.css'; const LoginForm = () => { const PHRASES = ["U got the wrong house fool!", "¿Te conozco?", "Hola :3", "¿Quién chota sos?🧐", "Identifícate", "Arto ahí ¿quién ere?"]; - const { login, error } = useContext(AuthContext); + const { login, error, clearError } = useContext(AuthContext); const [randomPhrase, setRandomPhrase] = useState(""); const navigate = useNavigate(); @@ -33,6 +33,8 @@ const LoginForm = () => { const handleChange = (e) => { const { name, value } = e.target; setFormState((prev) => ({ ...prev, [name]: value })); + + if (error) clearError(); }; const handleSubmit = async (e) => { diff --git a/src/components/Auth/RegisterForm.jsx b/src/components/Auth/RegisterForm.jsx index b454300..6c99002 100644 --- a/src/components/Auth/RegisterForm.jsx +++ b/src/components/Auth/RegisterForm.jsx @@ -1,6 +1,6 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { faUser } from '@fortawesome/free-solid-svg-icons'; -import { Form, Button, Alert, FloatingLabel} from 'react-bootstrap'; +import { faAt, faIdCard, faUser } from '@fortawesome/free-solid-svg-icons'; +import { Form, Button, Alert, FloatingLabel } from 'react-bootstrap'; import PasswordInput from './PasswordInput.jsx'; import { useContext, useState } from "react"; @@ -13,28 +13,38 @@ import ContentWrapper from '@/components/ContentWrapper.jsx'; import '@/css/LoginForm.css'; const RegisterForm = () => { - const { register, error } = useContext(AuthContext); + const { register, error, clearError } = useContext(AuthContext); const navigate = useNavigate(); const [formState, setFormState] = useState({ + displayName: "", username: "", + email: "", password: "" }); const handleChange = (e) => { const { name, value } = e.target; - setFormState((prev) => ({ ...prev, [name]: value })); + + setFormState((prev) => ({ + ...prev, + [name]: name === "displayName" ? value.toUpperCase() : value + })); + + if (error) clearError(); }; const handleSubmit = async (e) => { e.preventDefault(); - + const registerBody = { + displayName: formState.displayName ? formState.displayName.toUpperCase() : "", username: formState.username, + email: formState.email, password: formState.password, serviceId: 0 }; - + try { await register(registerBody); navigate("/"); @@ -50,6 +60,26 @@ const RegisterForm = () => {

Centro de cuentas

+ + + Nombre (será el usuario si se deja vacío) + + } + > + + + { /> + + + Email + + } + > + + + { setAuthStatus("unauthenticated"); }; + const clearError = () => setError(null); + return ( { register, logout, error, + clearError }} > {children} diff --git a/src/pages/Accounts.jsx b/src/pages/Accounts.jsx index 9ec3289..18efe22 100644 --- a/src/pages/Accounts.jsx +++ b/src/pages/Accounts.jsx @@ -12,6 +12,7 @@ import AccountCard from "@/components/Accounts/AccountCard"; import CustomModal from "@/components/CustomModal"; import { Button } from "react-bootstrap"; import { useState } from "react"; +import { useAuth } from "@/hooks/useAuth"; const Accounts = () => { const { config, configLoading } = useConfig(); @@ -41,6 +42,7 @@ const Accounts = () => { const AccountsContent = ({ reqConfig }) => { const { data, dataLoading, putData } = useDataContext(); + const { logout } = useAuth(); const [showConfirmModal, setShowConfirmModal] = useState(false); const [pendingAccountId, setPendingAccountId] = useState(null); const [pendingStatus, setPendingStatus] = useState(null); @@ -76,6 +78,10 @@ const AccountsContent = ({ reqConfig }) => { }, true ); + + if(updatedIdentity?.status == 0) { + logout(); + } } catch (err) { console.error(err); } @@ -87,7 +93,7 @@ const AccountsContent = ({ reqConfig }) => { ( { const { authStatus } = useAuth(); const navigate = useNavigate(); - if (authStatus == "authenticated") - navigate("/"); + useEffect(() => { + if (authStatus === "authenticated") { + navigate("/"); + } + }, [authStatus, navigate]); return (