From 944b5ed728189fa5faa87c27026e3bb97e4a6a0a Mon Sep 17 00:00:00 2001 From: CarolinaUniovi Date: Mon, 18 Mar 2024 23:04:05 +0100 Subject: [PATCH] register redirects to the game --- webapp/src/components/register/Register.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/webapp/src/components/register/Register.tsx b/webapp/src/components/register/Register.tsx index 452ab32..4d6ca01 100644 --- a/webapp/src/components/register/Register.tsx +++ b/webapp/src/components/register/Register.tsx @@ -3,6 +3,7 @@ import axios from 'axios'; import { Container, Typography, TextField, Snackbar, Stack, Button } from '@mui/material'; import { useTranslation } from 'react-i18next'; import './Register.scss'; +import { useNavigate } from "react-router-dom"; const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; @@ -11,6 +12,7 @@ type ActionProps = { } const Register = (props:ActionProps) => { + const navigate = useNavigate(); const { t } = useTranslation(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); @@ -22,6 +24,21 @@ const Register = (props:ActionProps) => { // checkear que el username no exista (tiene que ser unico) await axios.post(`${apiEndpoint}/adduser`, { username, password }); setOpenSnackbar(true); + + localStorage.clear(); + const user = await axios.post(`${apiEndpoint}/login`, { username, password }); + + console.log(user.data); + localStorage.setItem("username", user.data.username); + localStorage.setItem("score", user.data.totalScore); + localStorage.setItem("nWins", user.data.nWins); + localStorage.setItem("uuid", user.data.uuid); + localStorage.setItem("isAuthenticated", JSON.stringify(true)); + // Extract data from the response + localStorage.setItem('userUUID', user.data.uuid); + + setOpenSnackbar(true); + navigate("/game") } catch (error) { setError(error.response.data.error); }