Skip to content

Commit

Permalink
Fix user session (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
akileng56 authored Mar 27, 2024
1 parent c4aef45 commit 0033f5d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/login/login.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
setSessionLocation,
useConfig,
useConnectivity,
useSession,
} from "@openmrs/esm-framework";
import { getProvider, performLogin, useFacilityName } from "./login.resource";
import Logo from "./logo.component";
Expand All @@ -33,6 +34,7 @@ const Login: React.FC<LoginReferrer> = () => {
const { t } = useTranslation();
const location = useLocation();
const nav = useNavigate();
const { user } = useSession();
const { facilityName } = useFacilityName();
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
Expand All @@ -43,7 +45,7 @@ const Login: React.FC<LoginReferrer> = () => {
const formRef = useRef<HTMLFormElement>(null);
const [hasUserLocation, setHasUserLocation] = useState(false);
useEffect(() => {
if (hasUserLocation) {
if (hasUserLocation || user) {
clearCurrentUser();
refetchCurrentUser().then(() => {
const authenticated =
Expand All @@ -55,7 +57,14 @@ const Login: React.FC<LoginReferrer> = () => {
} else if (!username && location.pathname === "/login/confirm") {
nav("/login", { state: location.state });
}
}, [username, nav, location, hasUserLocation, config.links.loginSuccess]);
}, [
username,
nav,
location,
hasUserLocation,
config.links.loginSuccess,
user,
]);

const changeUsername = useCallback(
(evt: React.ChangeEvent<HTMLInputElement>) => setUsername(evt.target.value),
Expand Down

0 comments on commit 0033f5d

Please sign in to comment.