Improve backend connectivity check with early returns and Remove unrelated super admin check to focus on backend reachability

This commit is contained in:
mohadeseh safari committed 2025-04-27 12:57:38 -04:00
1 parent eec11f303c
commit 720f60cbb7
1 file changed
+7 -22
+7 -22
View File
@@ -59,38 +59,23 @@ const Login = () => {
const isReachable = await networkService.checkBackendReachability(); const isReachable = await networkService.checkBackendReachability();
setBackendReachable(isReachable); setBackendReachable(isReachable);
if (isReachable) { // Early return if backend is not reachable
// Only check if super admin exists if not already attempting to log in if (isReachable === false) {
// This allows users to log in even if system thinks no super admin exists // Show toast only on retry attempts
if (window.location.pathname === "/" || window.location.pathname === "") { if (isRetry) {
networkService
.doesSuperAdminExist()
.then((response) => {
if (response.data.data === false) {
// Add a toast notification instead of forcing redirect
createToast({ createToast({
body: t("noSuperAdminMessage"), body: t("backendStillUnreachable"),
type: "info"
}); });
} }
}) return;
.catch((error) => {
logger.error(error);
});
} }
// Only show reconnection toast if this was a retry attempt // Show reconnection toast if this was a retry attempt and backend is now reachable
if (isRetry) { if (isRetry) {
createToast({ createToast({
body: t("backendReconnected"), body: t("backendReconnected"),
}); });
} }
} else if (isRetry) {
// Only show still unreachable toast if this was a retry attempt
createToast({
body: t("backendStillUnreachable"),
});
}
} catch (error) { } catch (error) {
logger.error("Error checking backend connectivity:", error); logger.error("Error checking backend connectivity:", error);
setBackendReachable(false); setBackendReachable(false);