diff --git a/webapp/src/App.tsx b/webapp/src/App.tsx index b409ec4..8387448 100644 --- a/webapp/src/App.tsx +++ b/webapp/src/App.tsx @@ -1,26 +1,14 @@ import { BrowserRouter } from "react-router-dom"; import { AppRouter } from "./Router"; -import { createContext, useContext, useState } from "react" -import { User, UserContexType } from "./common/types"; -export const UserContext = createContext({} as UserContexType); -export const UserData = () => useContext(UserContext); + /** The old code is not in /pages/init/index.tsx and is shown as default */ function App() { - let myUser: User = { - name: "Usuario", points: "0", isAuthenticated: false - } - const [user, setUser] = useState(myUser); - - //const userProviderValue: UserContexType = useMemo(()=>({AuthUser : user, setAuthUser: setUser}), [user, setUser]) - return ( - - ); } diff --git a/webapp/src/common/types.tsx b/webapp/src/common/types.tsx deleted file mode 100644 index 9d21d86..0000000 --- a/webapp/src/common/types.tsx +++ /dev/null @@ -1,10 +0,0 @@ -export type User = { - name: string; - points: string; - isAuthenticated: boolean; - } - -export type UserContexType = { - AuthUser: User; - setAuthUser: (value: User) => void; -} \ No newline at end of file diff --git a/webapp/src/components/Login.tsx b/webapp/src/components/Login.tsx index 5be6982..7fa80d5 100644 --- a/webapp/src/components/Login.tsx +++ b/webapp/src/components/Login.tsx @@ -4,8 +4,6 @@ import axios from 'axios'; import { Container, Typography, TextField, Snackbar, Button, Stack } from '@mui/material'; import { useTranslation } from 'react-i18next'; import { useNavigate } from "react-router-dom"; -import { UserData } from 'src/App'; -import { User } from "../common/types"; type ActionProps = { @@ -20,7 +18,6 @@ const Login = (props: ActionProps) => { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); - const { setAuthUser} = UserData(); const [openSnackbar, setOpenSnackbar] = useState(false); const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; @@ -28,16 +25,14 @@ const Login = (props: ActionProps) => { const loginUser = async () => { try { - await axios.post(`${apiEndpoint}/login`, { username, password }); - - var user:User = { - name: username, - points: "10", - isAuthenticated: true - } - - - setAuthUser(user); + 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); // Extract data from the response setOpenSnackbar(true); diff --git a/webapp/src/pages/userProfile/index.tsx b/webapp/src/pages/userProfile/index.tsx index 054b5dc..0efe90f 100644 --- a/webapp/src/pages/userProfile/index.tsx +++ b/webapp/src/pages/userProfile/index.tsx @@ -1,17 +1,18 @@ import { useTranslation } from 'react-i18next'; -import { UserData } from 'src/App'; import { Container } from '@mui/material'; const ProfilePage = () => { const { t } = useTranslation(); - const {AuthUser} = UserData(); + const user = localStorage.getItem("username"); + const score = localStorage.getItem("totalScore"); + const nwins = localStorage.getItem("nwins"); + return(
-

{t('profile_name')}

-

{AuthUser.name}

-

{t('profile_points')}

-

{AuthUser.points}

+

{t('profile_name')} { JSON.stringify(user)}

+

{t('profile_points')} { JSON.stringify(Number(score)) }

+

{t('profile_nwins')} { JSON.stringify(Number(nwins)) }

)