Fixed login route and authentication guards.
This commit is contained in:
@@ -5,7 +5,7 @@ import { apiClient } from "../utils/httpClients.js";
|
||||
import MatchInfoCardDisplay from "../components/MatchInfoCardDisplay";
|
||||
import SportInfoCardDisplay from "../components/SportInfoCardDisplay";
|
||||
import AuthenticationGuard from "../components/AuthenticationGuard";
|
||||
import context from "../globals";
|
||||
import globals from "../globals";
|
||||
|
||||
export default class Dashboard extends React.Component {
|
||||
constructor(props) {
|
||||
@@ -18,7 +18,7 @@ export default class Dashboard extends React.Component {
|
||||
};
|
||||
}
|
||||
|
||||
static contextType = context;
|
||||
static contextType = globals;
|
||||
|
||||
async componentDidMount() {
|
||||
this.setState({ user: this.context.user });
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import React from "react";
|
||||
import { Alert, Button, Card, Container, Form } from "react-bootstrap";
|
||||
import context from "../globals";
|
||||
import globals from "../globals";
|
||||
import { apiClient } from "../utils/httpClients";
|
||||
|
||||
export default class Login extends React.Component {
|
||||
@@ -15,24 +15,25 @@ export default class Login extends React.Component {
|
||||
this.attemptLogin = this.attemptLogin.bind(this);
|
||||
}
|
||||
|
||||
static contextType = context;
|
||||
static contextType = globals;
|
||||
|
||||
async componentDidMount() {
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
if (this.context.user) {
|
||||
this.context.navigate("/dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
async attemptLogin(e) {
|
||||
e.preventDefault();
|
||||
const loginResponse = await apiClient.post("/user/login", {
|
||||
email: this.state.email,
|
||||
password: this.state.password,
|
||||
}, {
|
||||
validateStatus: function (status) {
|
||||
return status === 200 || status === 401 || status === 400;
|
||||
}
|
||||
});
|
||||
if (loginResponse.status === 200) {
|
||||
this.context.user = loginResponse.data;
|
||||
this.context.navigate("/dashboard", { replace: true });
|
||||
this.context.update({ user: loginResponse.data });
|
||||
} else if (loginResponse.status === 401) {
|
||||
this.setState({ errorDisplayed: true });
|
||||
}
|
||||
|
@@ -11,15 +11,15 @@ export default class Logout extends React.Component {
|
||||
|
||||
async componentDidMount() {
|
||||
const logoutResponse = await apiClient.get("/user/logout");
|
||||
if (logoutResponse.status === 401) {
|
||||
globals.navigate("/dashboard", { replace: true });
|
||||
} else {
|
||||
if (logoutResponse.status === 200) {
|
||||
this.redirectTimer = setTimeout(() => {
|
||||
globals.navigate("/", { replace: true });
|
||||
this.context.navigate("/", { replace: true });
|
||||
}, 2000);
|
||||
} else if (logoutResponse.status == 401) {
|
||||
this.context.navigate("/", { replace: true });
|
||||
}
|
||||
|
||||
globals.setUser(null);
|
||||
this.context.update({ user: null });
|
||||
}
|
||||
|
||||
async componentWillUnmount() {
|
||||
|
@@ -1,15 +1,8 @@
|
||||
import React from "react";
|
||||
import { Button, Table } from "react-bootstrap";
|
||||
import "../styles/Admin.css";
|
||||
import { globalContext } from "../context";
|
||||
import { needUser } from "../utils/routing";
|
||||
//import Button from "@mui/material/Button";
|
||||
// import Typography from "@mui/material/Typography";
|
||||
// import Container from "@mui/material/Container";
|
||||
// import { TableContainer, TableCell, Table, TableBody, TableRow, TableHead, Paper } from "@mui/material";
|
||||
// import { apiClient } from "../utils/httpClients.js";
|
||||
// import MatchInfoCardDisplay from "../components/MatchInfoCardDisplay";
|
||||
// import { needUser } from "../utils/routing.js";
|
||||
import globals from "../globals";
|
||||
|
||||
export default class Admin extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@@ -40,10 +33,9 @@ export default class Admin extends React.Component {
|
||||
|
||||
}
|
||||
|
||||
static contextType = globalContext;
|
||||
static contextType = globals;
|
||||
|
||||
async componentDidMount() {
|
||||
await needUser(this.context.navigate);
|
||||
}
|
||||
|
||||
DeleteButton() {
|
||||
|
Reference in New Issue
Block a user