From c05dc62c8c29e062360e7147cf27ae1b8bf0ccb2 Mon Sep 17 00:00:00 2001 From: jnsereko Date: Sun, 11 Dec 2022 16:18:52 +0300 Subject: [PATCH] O3-1444: Expired login session keeps the location page stuck --- .../src/login/login.component.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/apps/esm-login-app/src/login/login.component.tsx b/packages/apps/esm-login-app/src/login/login.component.tsx index a989269f4..7eccff6ea 100644 --- a/packages/apps/esm-login-app/src/login/login.component.tsx +++ b/packages/apps/esm-login-app/src/login/login.component.tsx @@ -9,7 +9,14 @@ import { } from "@carbon/react"; import { ArrowLeft, ArrowRight } from "@carbon/react/icons"; import { useTranslation } from "react-i18next"; -import { useConfig, interpolateUrl, useSession } from "@openmrs/esm-framework"; +import { + useConfig, + interpolateUrl, + useSession, + refetchCurrentUser, + clearCurrentUser, + getSessionStore, +} from "@openmrs/esm-framework"; import { performLogin } from "./login.resource"; import styles from "./login.scss"; @@ -44,7 +51,14 @@ const Login: React.FC = ({ isLoginEnabled }) => { useEffect(() => { if (user) { - navigate("/login/location", { state: location.state }); + clearCurrentUser(); + refetchCurrentUser().then(() => { + const authenticated = + getSessionStore().getState().session.authenticated; + if (authenticated) { + navigate("/login/location", { state: location.state }); + } + }); } else if (!username && location.pathname === "/login/confirm") { navigate("/login", { state: location.state }); }