diff --git a/src/client/src/FrontPage.js b/src/client/src/FrontPage.js index 74025ae..f27f039 100644 --- a/src/client/src/FrontPage.js +++ b/src/client/src/FrontPage.js @@ -6,6 +6,7 @@ import TournamentManager from "./TournamentManager.js"; import TournamentHistory from "./TournamentHistory"; import TournamentTeams from "./TournamentTeams"; import LoginPage from "./LoginPage"; +import ProfilePage from "./ProfilePage"; import AppBar from './components/AsuraBar'; import { Button, Container, Typography, Box, Stack, Card, CardContent, CardMedia, Paper, Grid, Icon, TextField } from "@mui/material"; import AddCircleIcon from '@mui/icons-material/AddCircle'; @@ -194,6 +195,40 @@ function Home() { ); } +class LoginManager { + user = { + name: "", + email: "", + googleId: "", + asuraId: -1, + isManager: false + }; + + checkLogin() { + fetch(process.env.REACT_APP_API_URL + `/users/getSavedUser`) + .then(res => res.json()) + .then(data => { + if (data.status !== "OK") { + console.error(data); + return; + } + console.log(data); + this.user = data.data; + }) + .catch((err) => console.log(err.message)); + } + + isLoggedIn() { + return this.user.googleId !== undefined && this.user.googleId !== "" && this.user.asuraId !== undefined && this.user.asuraId !== -1; + } + isManager() { + return this.isLoggedIn() && this.user.isManager; + } +} + +let login = new LoginManager(); +login.checkLogin(); + export default function App() { return ( @@ -206,6 +241,7 @@ export default function App() { } /> } /> } /> + } /> diff --git a/src/client/src/ProfilePage.js b/src/client/src/ProfilePage.js new file mode 100644 index 0000000..2738e96 --- /dev/null +++ b/src/client/src/ProfilePage.js @@ -0,0 +1,27 @@ +import * as React from "react"; +import { BrowserRouter as Router, Link, Route, Routes } from "react-router-dom"; +import AppBar from "./components/AsuraBar"; +import ErrorSnackbar from "./components/ErrorSnackbar"; +import { Button, TextField, Stack, InputLabel, Select, Container, Slider, Paper, Box, Grid, Typography } from '@mui/material'; + +export default function ProfilePage(props) { + if (!props.login) { + return

Something went very wrong

+ } + console.log(props.login.user); + return (<> + + + {props.login.isLoggedIn ? <> + + + + :<> + + You are not logged in. + + } + + + ) +} \ No newline at end of file