Skip to content

Commit

Permalink
Solucionado error con los mensajes de error en el login
Browse files Browse the repository at this point in the history
  • Loading branch information
CANCI0 committed Apr 1, 2024
1 parent b82cff3 commit 5b0a153
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
33 changes: 17 additions & 16 deletions webapp/src/components/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<Flex alignItems="center" justifyContent="space-between" mt={4} w="100%">
<Box pr={5}>

</Box>
<Box pr={5}></Box>
<Heading pl={6} as="h1" size="xl" color="teal.500">
WIQ
</Heading>
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/Register/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 5b0a153

Please sign in to comment.