From 5b0a15335aaa445389be7e784f536f39e659b363 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Mon, 1 Apr 2024 19:47:10 +0200 Subject: [PATCH] Solucionado error con los mensajes de error en el login --- webapp/src/components/Login/Login.js | 33 +++++++++++----------- webapp/src/components/Register/Register.js | 2 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/webapp/src/components/Login/Login.js b/webapp/src/components/Login/Login.js index 2385118d..c95e039f 100644 --- a/webapp/src/components/Login/Login.js +++ b/webapp/src/components/Login/Login.js @@ -32,30 +32,31 @@ const Login = () => { const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || "http://localhost:8000"; - const loginUser = async () => { - try { - const response = await axios.post(`${apiEndpoint}/login`, { + const loginUser = () => { + axios + .post(`${apiEndpoint}/login`, { username, password, - }); - const token = response.data; + }) + .then((response) => { + const token = response.data; - setLoginSuccess(true); - setOpenSnackbar(true); - localStorage.setItem("token", token); - localStorage.setItem("username", username); - navigate("/home"); - } catch (err) { - setError(err.message); - } + setLoginSuccess(true); + setOpenSnackbar(true); + localStorage.setItem("token", token); + localStorage.setItem("username", username); + navigate("/home"); + }) + .catch((err) => { + console.log(err); + setError(err.response.data.error); + }); }; return ( <> - - - + WIQ diff --git a/webapp/src/components/Register/Register.js b/webapp/src/components/Register/Register.js index f338735a..d741cc3e 100644 --- a/webapp/src/components/Register/Register.js +++ b/webapp/src/components/Register/Register.js @@ -38,7 +38,7 @@ const AddUser = () => { axios .post(`${apiEndpoint}/adduser`, { username, password }) .then(() => setOpenSnackbar(true)) - .catch((error) => setError(error.message)); + .catch((error) => setError(err.response.data.error)); }; return (