ny klæbb
This commit is contained in:
parent
c20cea953d
commit
2677793b28
|
@ -200,48 +200,72 @@ 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.data);
|
||||
return;
|
||||
}
|
||||
console.log(data);
|
||||
this.user = data.data;
|
||||
return this.user;
|
||||
})
|
||||
.catch((err) => console.log(err.message));
|
||||
}
|
||||
// class LoginManager {
|
||||
// checkLogin() {
|
||||
// fetch(process.env.REACT_APP_API_URL + `/users/getSavedUser`)
|
||||
// .then(res => res.json())
|
||||
// .then(data => {
|
||||
// if (data.status !== "OK") {
|
||||
// console.error(data.data);
|
||||
// return;
|
||||
// }
|
||||
// console.log(data);
|
||||
// setUser(data.data);
|
||||
// return user;
|
||||
// })
|
||||
// .catch((err) => console.log(err.message));
|
||||
// }
|
||||
|
||||
isLoggedIn() {
|
||||
let loggedIn = this.user.googleId !== "" && this.user.asuraId !== -1;
|
||||
console.log(loggedIn);
|
||||
return loggedIn;
|
||||
}
|
||||
isManager() {
|
||||
return this.isLoggedIn() && this.user.isManager;
|
||||
}
|
||||
}
|
||||
// isLoggedIn() {
|
||||
// let loggedIn = user.googleId !== "" && user.asuraId !== -1;
|
||||
// console.log(loggedIn);
|
||||
// return loggedIn;
|
||||
// }
|
||||
// isManager() {
|
||||
// return this.isLoggedIn() && user.isManager;
|
||||
// }
|
||||
// }
|
||||
|
||||
let login = new LoginManager();
|
||||
login.checkLogin();
|
||||
// let login = new LoginManager();
|
||||
// login.checkLogin();
|
||||
|
||||
|
||||
let showSuccess = (message) => {};
|
||||
let showError = (message) => {};
|
||||
|
||||
export default function App() {
|
||||
const [user, setUser] = React.useState({});
|
||||
let checkLogin = () => {
|
||||
fetch(process.env.REACT_APP_API_URL + `/users/getSavedUser`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.status !== "OK") {
|
||||
setUser({
|
||||
isManager: false,
|
||||
isLoggedIn: false
|
||||
});
|
||||
console.error(data.data);
|
||||
return;
|
||||
}
|
||||
console.log(data);
|
||||
let u = data.data;
|
||||
u.isLoggedIn = true;
|
||||
setUser(u);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err.message);
|
||||
setUser({
|
||||
isManager: false,
|
||||
isLoggedIn: false
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
checkLogin();
|
||||
}, []);
|
||||
|
||||
const [openError, setOpenError] = React.useState(false);
|
||||
const [errorMessage, setErrorMessage] = React.useState("");
|
||||
showError = (message) => {
|
||||
|
@ -269,7 +293,7 @@ export default function App() {
|
|||
<Route path="/tournament/:tournamentId/teams" element={<TournamentTeams showError={showError} showSuccess={showSuccess} />} />
|
||||
<Route path="/history" element={<TournamentHistory showError={showError} showSuccess={showSuccess} />} />
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
<Route path="/profile" element={<ProfilePage login={login} />} />
|
||||
<Route path="/profile" element={<ProfilePage user={user} checkLogin={checkLogin} />} />
|
||||
<Route path="/admins" element={<AdminsOverview />} />
|
||||
</Routes>
|
||||
</Router>
|
||||
|
|
|
@ -5,17 +5,11 @@ 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) {
|
||||
const [loggedIn, setLoggedIn] = React.useState(props.login.isLoggedIn());
|
||||
React.useEffect(() => {
|
||||
setLoggedIn(props.login.isLoggedIn());
|
||||
}, [props.login]);
|
||||
|
||||
|
||||
let user = props.login.user;
|
||||
let user = props.user;
|
||||
return (<>
|
||||
<AppBar pageTitle="Profile" />
|
||||
<Container sx={{minHeight: "30vh", width: "90vw", padding: "20px 20px"}} component={Container} direction="column" align="center">
|
||||
{loggedIn ? <>
|
||||
{user.isLoggedIn ? <>
|
||||
<Paper sx={{minHeight: "30vh", width: "90vw", margin: "10px auto"}} component={Stack} direction="column" justifyContent="center">
|
||||
<div align="center">
|
||||
<h2><b>Your profile</b></h2>
|
||||
|
|
Loading…
Reference in New Issue