Skip to content

Commit

Permalink
Ahora el registro redirecciona a Home
Browse files Browse the repository at this point in the history
  • Loading branch information
iyanfdezz committed Apr 2, 2024
1 parent b0ed48d commit c86d842
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion webapp/src/components/Register/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Spacer,
Switch
} from "@chakra-ui/react";
import { useNavigate } from "react-router-dom";
import Footer from "../Footer/Footer";

const apiEndpoint =
Expand All @@ -29,6 +30,7 @@ const AddUser = () => {
const [passwordR, setPasswordR] = useState("");
const [error, setError] = useState("");
const [openSnackbar, setOpenSnackbar] = useState(false);
const navigate = useNavigate();

const handleRegister = () => {
if (password !== passwordR) {
Expand All @@ -37,7 +39,13 @@ const AddUser = () => {
}
axios
.post(`${apiEndpoint}/adduser`, { username, password })
.then(() => setOpenSnackbar(true))
.then((response) => {
const { token } = response.data;
setOpenSnackbar(true);
localStorage.setItem("token", token);
localStorage.setItem("username", username);
navigate("/home");
})
.catch((err) => setError(err.response.data.error));
};

Expand Down

0 comments on commit c86d842

Please sign in to comment.