From 64b2718673d39a16744e45836af78762a3deebb1 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 17 Jul 2023 19:06:31 -0400 Subject: [PATCH] fix: Race condition on login --- app/components/Authenticated.tsx | 5 +++++ app/stores/AuthStore.ts | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/app/components/Authenticated.tsx b/app/components/Authenticated.tsx index 4573af668..924e5da8d 100644 --- a/app/components/Authenticated.tsx +++ b/app/components/Authenticated.tsx @@ -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 ; + } + void auth.logout(true); return ; }; diff --git a/app/stores/AuthStore.ts b/app/stores/AuthStore.ts index 1ca3eaec4..51856ce4e 100644 --- a/app/stores/AuthStore.ts +++ b/app/stores/AuthStore.ts @@ -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; } };