Authentication guard will now always refresh user identity.

This commit is contained in:
Harrison Deng 2022-04-07 18:00:14 -05:00
parent e7d689cdde
commit a0a347e0c2

View File

@ -10,14 +10,13 @@ export default class AuthenticationGuard extends React.Component {
static contextType = globals; static contextType = globals;
async componentDidMount() { async componentDidMount() {
if (!this.context.user) { 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 }); } else if (userDataResponse.status == 401) {
} else if (userDataResponse.status == 401) { this.context.navigate("/signup", { replace: true });
this.context.navigate("/signup", { replace: true }); }
} if (this.context.user && this.context.user.accessLevel < this.props.accessLevel) {
} else if (this.context.user.accessLevel < this.props.accessLevel) {
this.context.navigate("/", { replace: true }); this.context.navigate("/", { replace: true });
} }
} }