diff --git a/sports-matcher/client/src/components/AuthenticationGuard.js b/sports-matcher/client/src/components/AuthenticationGuard.js index 2ab5433..d9f3634 100644 --- a/sports-matcher/client/src/components/AuthenticationGuard.js +++ b/sports-matcher/client/src/components/AuthenticationGuard.js @@ -1,6 +1,7 @@ import React from "react"; import globals from "../globals"; import { apiClient } from "../utils/httpClients"; +import propTypes from "prop-types"; export default class AuthenticationGuard extends React.Component { constructor(props) { @@ -14,12 +15,22 @@ export default class AuthenticationGuard extends React.Component { if (userDataResponse.status === 200) { this.context.update({ user: userDataResponse.data }); } else if (userDataResponse.status == 401) { - this.context.navigate("/signup"); + this.context.navigate("/signup", { replace: true }); } + } else if (this.context.user.accessLevel < this.props.accessLevel) { + this.context.navigate("/", { replace: true }); } } render() { return null; } -} \ No newline at end of file +} + +AuthenticationGuard.defaultProps = { + accessLevel: 0 +}; + +AuthenticationGuard.propTypes = { + accessLevel: propTypes.number, +}; \ No newline at end of file diff --git a/sports-matcher/client/src/pages/NewAdmin.js b/sports-matcher/client/src/pages/NewAdmin.js index b8e4c82..a224a24 100644 --- a/sports-matcher/client/src/pages/NewAdmin.js +++ b/sports-matcher/client/src/pages/NewAdmin.js @@ -2,6 +2,7 @@ import React from "react"; import { Button, Table } from "react-bootstrap"; import "../styles/Admin.css"; import globals from "../globals"; +import AuthenticationGuard from "../components/AuthenticationGuard"; export default class Admin extends React.Component { constructor(props) { @@ -175,37 +176,40 @@ export default class Admin extends React.Component { render() { return ( - +
+ + -
-

Administration

- - -
- - {this.renderTableHead()} - - {this.renderTableData()} - {/* {this.matchUserTableData()} */} - -
+
+

Administration

+ + +
+ + {this.renderTableHead()} + + {this.renderTableData()} + {/* {this.matchUserTableData()} */} + +
-
+ +
); } } \ No newline at end of file