Authentication guard now takes in a access level prop.
This commit is contained in:
parent
0e218750f8
commit
525c2b6d5a
@ -1,6 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import globals from "../globals";
|
import globals from "../globals";
|
||||||
import { apiClient } from "../utils/httpClients";
|
import { apiClient } from "../utils/httpClients";
|
||||||
|
import propTypes from "prop-types";
|
||||||
|
|
||||||
export default class AuthenticationGuard extends React.Component {
|
export default class AuthenticationGuard extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -14,8 +15,10 @@ export default class AuthenticationGuard extends React.Component {
|
|||||||
if (userDataResponse.status === 200) {
|
if (userDataResponse.status === 200) {
|
||||||
this.context.update({ user: userDataResponse.data });
|
this.context.update({ user: userDataResponse.data });
|
||||||
} else if (userDataResponse.status == 401) {
|
} 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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,3 +26,11 @@ export default class AuthenticationGuard extends React.Component {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AuthenticationGuard.defaultProps = {
|
||||||
|
accessLevel: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
AuthenticationGuard.propTypes = {
|
||||||
|
accessLevel: propTypes.number,
|
||||||
|
};
|
@ -2,6 +2,7 @@ import React from "react";
|
|||||||
import { Button, Table } from "react-bootstrap";
|
import { Button, Table } from "react-bootstrap";
|
||||||
import "../styles/Admin.css";
|
import "../styles/Admin.css";
|
||||||
import globals from "../globals";
|
import globals from "../globals";
|
||||||
|
import AuthenticationGuard from "../components/AuthenticationGuard";
|
||||||
|
|
||||||
export default class Admin extends React.Component {
|
export default class Admin extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -175,6 +176,8 @@ export default class Admin extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
<div className="page-root">
|
||||||
|
<AuthenticationGuard accessLevel={3} />
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
|
||||||
<div className='center'>
|
<div className='center'>
|
||||||
@ -206,6 +209,7 @@ export default class Admin extends React.Component {
|
|||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user