Authentication guard now takes in a access level prop.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AuthenticationGuard.defaultProps = {
|
||||
accessLevel: 0
|
||||
};
|
||||
|
||||
AuthenticationGuard.propTypes = {
|
||||
accessLevel: propTypes.number,
|
||||
};
|
Reference in New Issue
Block a user