fix: Race condition on login
This commit is contained in:
@@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { Redirect } from "react-router-dom";
|
import { Redirect } from "react-router-dom";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import { changeLanguage } from "~/utils/language";
|
import { changeLanguage } from "~/utils/language";
|
||||||
|
import LoadingIndicator from "./LoadingIndicator";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
children: JSX.Element;
|
children: JSX.Element;
|
||||||
@@ -24,6 +25,10 @@ const Authenticated = ({ children }: Props) => {
|
|||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auth.isFetching) {
|
||||||
|
return <LoadingIndicator />;
|
||||||
|
}
|
||||||
|
|
||||||
void auth.logout(true);
|
void auth.logout(true);
|
||||||
return <Redirect to="/" />;
|
return <Redirect to="/" />;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ export default class AuthStore {
|
|||||||
@observable
|
@observable
|
||||||
isSaving = false;
|
isSaving = false;
|
||||||
|
|
||||||
|
@observable
|
||||||
|
isFetching = true;
|
||||||
|
|
||||||
/* Whether the user is currently suspended. */
|
/* Whether the user is currently suspended. */
|
||||||
@observable
|
@observable
|
||||||
isSuspended = false;
|
isSuspended = false;
|
||||||
@@ -178,6 +181,8 @@ export default class AuthStore {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
fetch = async () => {
|
fetch = async () => {
|
||||||
|
this.isFetching = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await client.post("/auth.info", undefined, {
|
const res = await client.post("/auth.info", undefined, {
|
||||||
credentials: "same-origin",
|
credentials: "same-origin",
|
||||||
@@ -234,6 +239,8 @@ export default class AuthStore {
|
|||||||
this.isSuspended = true;
|
this.isSuspended = true;
|
||||||
this.suspendedContactEmail = err.data.adminEmail;
|
this.suspendedContactEmail = err.data.adminEmail;
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
this.isFetching = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user