Login endpoint now returns the user profile.
This commit is contained in:
@@ -4,8 +4,8 @@ import "../styles/Dashboard.css";
|
||||
import { apiClient } from "../utils/httpClients.js";
|
||||
import MatchInfoCardDisplay from "../components/MatchInfoCardDisplay";
|
||||
import SportInfoCardDisplay from "../components/SportInfoCardDisplay";
|
||||
import { globalContext } from "../context";
|
||||
import AuthenticationGuard from "../components/AuthenticationGuard";
|
||||
import context from "../globals";
|
||||
|
||||
export default class Dashboard extends React.Component {
|
||||
constructor(props) {
|
||||
@@ -18,7 +18,7 @@ export default class Dashboard extends React.Component {
|
||||
};
|
||||
}
|
||||
|
||||
static contextType = globalContext;
|
||||
static contextType = context;
|
||||
|
||||
async componentDidMount() {
|
||||
this.setState({ user: this.context.user });
|
||||
|
@@ -1,8 +1,7 @@
|
||||
import React from "react";
|
||||
import { Alert, Button, Card, Container, Form } from "react-bootstrap";
|
||||
import { globalContext } from "../context";
|
||||
import context from "../globals";
|
||||
import { apiClient } from "../utils/httpClients";
|
||||
import AuthenticationGuard from "../components/AuthenticationGuard";
|
||||
|
||||
export default class Login extends React.Component {
|
||||
constructor(props) {
|
||||
@@ -16,7 +15,7 @@ export default class Login extends React.Component {
|
||||
this.attemptLogin = this.attemptLogin.bind(this);
|
||||
}
|
||||
|
||||
static contextType = globalContext;
|
||||
static contextType = context;
|
||||
|
||||
async componentDidMount() {
|
||||
}
|
||||
@@ -32,6 +31,7 @@ export default class Login extends React.Component {
|
||||
}
|
||||
});
|
||||
if (loginResponse.status === 200) {
|
||||
this.context.user = loginResponse.data;
|
||||
this.context.navigate("/dashboard", { replace: true });
|
||||
} else if (loginResponse.status === 401) {
|
||||
this.setState({ errorDisplayed: true });
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import React from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import globals from "../globals";
|
||||
import { apiClient } from "../utils/httpClients";
|
||||
|
||||
export default class Logout extends React.Component {
|
||||
@@ -7,16 +7,19 @@ export default class Logout extends React.Component {
|
||||
super(props);
|
||||
}
|
||||
|
||||
static contextType = globals;
|
||||
|
||||
async componentDidMount() {
|
||||
const logoutResponse = await apiClient.get("/user/logout");
|
||||
let navigation = useNavigate();
|
||||
if (logoutResponse.status === 401) {
|
||||
navigation("/dashboard", { replace: true });
|
||||
globals.navigate("/dashboard", { replace: true });
|
||||
} else {
|
||||
this.redirectTimer = setTimeout(() => {
|
||||
navigation("/", { replace: true });
|
||||
globals.navigate("/", { replace: true });
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
globals.setUser(null);
|
||||
}
|
||||
|
||||
async componentWillUnmount() {
|
||||
|
Reference in New Issue
Block a user