If the user session has expired, update context appropriately.

This commit is contained in:
Harrison Deng 2022-04-07 20:47:12 -05:00
parent 90040f9049
commit 753669c0af

View File

@ -13,15 +13,16 @@ export default class AuthenticationGuard extends React.Component {
let userDataResponse = await apiClient.get("/user"); let userDataResponse = await apiClient.get("/user");
if (userDataResponse.status === 200) { if (userDataResponse.status === 200) {
this.context.update({ user: userDataResponse.data }); this.context.update({ user: userDataResponse.data });
if (this.context.user && this.context.user.accessLevel < this.props.accessLevel) {
this.context.navigate("/", { replace: true });
}
} else if (userDataResponse.status == 401) { } else if (userDataResponse.status == 401) {
this.context.navigate("/signup", { replace: true }); this.context.navigate("/signup", { replace: true });
this.context.update({ user: null });
} }
} }
componentDidUpdate() { componentDidUpdate() {
if (this.context.user && this.context.user.accessLevel < this.props.accessLevel) {
this.context.navigate("/", { replace: true });
}
} }
render() { render() {