fix: Race condition on login

This commit is contained in:
Tom Moor
2023-07-17 19:06:31 -04:00
parent 4b14fa5dd7
commit 64b2718673
2 changed files with 12 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next";
import { Redirect } from "react-router-dom";
import useStores from "~/hooks/useStores";
import { changeLanguage } from "~/utils/language";
import LoadingIndicator from "./LoadingIndicator";
type Props = {
children: JSX.Element;
@@ -24,6 +25,10 @@ const Authenticated = ({ children }: Props) => {
return children;
}
if (auth.isFetching) {
return <LoadingIndicator />;
}
void auth.logout(true);
return <Redirect to="/" />;
};

View File

@@ -81,6 +81,9 @@ export default class AuthStore {
@observable
isSaving = false;
@observable
isFetching = true;
/* Whether the user is currently suspended. */
@observable
isSuspended = false;
@@ -178,6 +181,8 @@ export default class AuthStore {
@action
fetch = async () => {
this.isFetching = true;
try {
const res = await client.post("/auth.info", undefined, {
credentials: "same-origin",
@@ -234,6 +239,8 @@ export default class AuthStore {
this.isSuspended = true;
this.suspendedContactEmail = err.data.adminEmail;
}
} finally {
this.isFetching = false;
}
};