diff --git a/sports-matcher/client/src/components/AuthenticationGuard.js b/sports-matcher/client/src/components/AuthenticationGuard.js index 93fbd7d..130c473 100644 --- a/sports-matcher/client/src/components/AuthenticationGuard.js +++ b/sports-matcher/client/src/components/AuthenticationGuard.js @@ -13,15 +13,16 @@ export default class AuthenticationGuard extends React.Component { let userDataResponse = await apiClient.get("/user"); if (userDataResponse.status === 200) { 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) { this.context.navigate("/signup", { replace: true }); + this.context.update({ user: null }); } } componentDidUpdate() { - if (this.context.user && this.context.user.accessLevel < this.props.accessLevel) { - this.context.navigate("/", { replace: true }); - } } render() {