Start LoginManager

This commit is contained in:
Felix Albrigtsen 2022-04-23 10:20:24 +02:00
parent 10476cd415
commit d69b3a1b2c
2 changed files with 63 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import TournamentManager from "./TournamentManager.js";
import TournamentHistory from "./TournamentHistory"; import TournamentHistory from "./TournamentHistory";
import TournamentTeams from "./TournamentTeams"; import TournamentTeams from "./TournamentTeams";
import LoginPage from "./LoginPage"; import LoginPage from "./LoginPage";
import ProfilePage from "./ProfilePage";
import AppBar from './components/AsuraBar'; import AppBar from './components/AsuraBar';
import { Button, Container, Typography, Box, Stack, Card, CardContent, CardMedia, Paper, Grid, Icon, TextField } from "@mui/material"; import { Button, Container, Typography, Box, Stack, Card, CardContent, CardMedia, Paper, Grid, Icon, TextField } from "@mui/material";
import AddCircleIcon from '@mui/icons-material/AddCircle'; 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() { export default function App() {
return ( return (
<React.StrictMode> <React.StrictMode>
@ -206,6 +241,7 @@ export default function App() {
<Route path="/tournament/:tournamentId/teams" element={<TournamentTeams />} /> <Route path="/tournament/:tournamentId/teams" element={<TournamentTeams />} />
<Route path="/history" element={<TournamentHistory />} /> <Route path="/history" element={<TournamentHistory />} />
<Route path="/login" element={<LoginPage />} /> <Route path="/login" element={<LoginPage />} />
<Route path="/profile" element={<ProfilePage login={login} />} />
</Routes> </Routes>
</Router> </Router>
</React.StrictMode> </React.StrictMode>

View File

@ -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 <h1>Something went very wrong</h1>
}
console.log(props.login.user);
return (<>
<AppBar pageTitle="Profile" />
<Container sx={{minHeight: "30vh", width: "90vw", padding: "20px 20px"}} component={Container} direction="column" align="center">
{props.login.isLoggedIn ? <>
<Box sx={{ padding: "20px", width: "90vw", height: "30vh", display: "flex", flexDirection: "column", justifyContent: "space-between", alignItems: "center", alignContent: "center", flexGrow: 1}}>
</Box>
</>:<>
<Box sx={{ padding: "20px", width: "90vw", height: "30vh", display: "flex", flexDirection: "column", justifyContent: "space-between", alignItems: "center", alignContent: "center", flexGrow: 1}}>
You are not logged in.
</Box>
</>}
</Container>
</>)
}