Implemented component version of authentication guard.
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 { globalContext } from "../context";
|
||||
import { needUser } from "../utils/routing";
|
||||
import AuthenticationGuard from "../components/AuthenticationGuard";
|
||||
|
||||
export default class Dashboard extends React.Component {
|
||||
constructor(props) {
|
||||
@@ -21,7 +21,7 @@ export default class Dashboard extends React.Component {
|
||||
static contextType = globalContext;
|
||||
|
||||
async componentDidMount() {
|
||||
await needUser(this.context.navigate);
|
||||
this.setState({ user: this.context.user });
|
||||
await this.latestMatches();
|
||||
await this.availableSports();
|
||||
}
|
||||
@@ -41,29 +41,32 @@ export default class Dashboard extends React.Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<React.Fragment>
|
||||
<h1></h1>
|
||||
<InputGroup className="w-50">
|
||||
<FormControl
|
||||
placeholder="Search for Matches"
|
||||
aria-label="Search Bar"
|
||||
aria-describedby="basic-addon2"
|
||||
/>
|
||||
<Button variant="outline-secondary" id="button-addon2">
|
||||
Search
|
||||
</Button>
|
||||
</InputGroup>
|
||||
<div className="p-4">
|
||||
<h2>Available Matches</h2>
|
||||
<MatchInfoCardDisplay recommendedmatches={this.state.displayedMatches} />
|
||||
</div>
|
||||
<div className="p-4">
|
||||
<h2>Available Sports</h2>
|
||||
<SportInfoCardDisplay recommendedsports={this.state.displayedSports} />
|
||||
</div>
|
||||
<div className="page-root">
|
||||
<AuthenticationGuard />
|
||||
<React.Fragment>
|
||||
<h1></h1>
|
||||
<InputGroup className="w-50">
|
||||
<FormControl
|
||||
placeholder="Search for Matches"
|
||||
aria-label="Search Bar"
|
||||
aria-describedby="basic-addon2"
|
||||
/>
|
||||
<Button variant="outline-secondary" id="button-addon2">
|
||||
Search
|
||||
</Button>
|
||||
</InputGroup>
|
||||
<div className="p-4">
|
||||
<h2>Available Matches</h2>
|
||||
<MatchInfoCardDisplay recommendedmatches={this.state.displayedMatches} />
|
||||
</div>
|
||||
<div className="p-4">
|
||||
<h2>Available Sports</h2>
|
||||
<SportInfoCardDisplay recommendedsports={this.state.displayedSports} />
|
||||
</div>
|
||||
|
||||
|
||||
</React.Fragment>
|
||||
</React.Fragment>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
@@ -2,7 +2,7 @@ import React from "react";
|
||||
import { Alert, Button, Card, Container, Form } from "react-bootstrap";
|
||||
import { globalContext } from "../context";
|
||||
import { apiClient } from "../utils/httpClients";
|
||||
import { guard } from "../utils/routing";
|
||||
import AuthenticationGuard from "../components/AuthenticationGuard";
|
||||
|
||||
export default class Login extends React.Component {
|
||||
constructor(props) {
|
||||
@@ -19,14 +19,6 @@ export default class Login extends React.Component {
|
||||
static contextType = globalContext;
|
||||
|
||||
async componentDidMount() {
|
||||
try {
|
||||
const getUserResponse = await apiClient.get("/user");
|
||||
guard(this.context.navigate, () => getUserResponse.status === 401, "/dashboard"); // If it's not 401, then we redirect to dashboard.
|
||||
} catch (error) {
|
||||
if (error.message !== "Request failed with status code 401") {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async attemptLogin(e) {
|
||||
|
Reference in New Issue
Block a user