diff --git a/backend/services/kuma_client.py b/backend/services/kuma_client.py index 813dbfa..704437f 100644 --- a/backend/services/kuma_client.py +++ b/backend/services/kuma_client.py @@ -128,15 +128,27 @@ class UptimeKumaClient: else: result = api.login(username, password) + # Check if 2FA is required + if result.get("tokenRequired"): + api.disconnect() + raise Exception("2FA token required. Please enter your TOTP code.") + token = result.get("token") - if token: - save_token(token) - self._token = token + if not token: + api.disconnect() + raise Exception("Login failed: No authentication token received") + + save_token(token) + self._token = token api.disconnect() return {"success": True, "message": "Login successful"} except Exception as e: - raise Exception(f"Login failed: {str(e)}") + error_msg = str(e) + # Re-raise with clear message for 2FA requirement + if "tokenRequired" in error_msg or "2fa" in error_msg.lower(): + raise Exception("2FA token required. Please enter your TOTP code.") + raise Exception(f"Login failed: {error_msg}") def is_authenticated(self) -> bool: """Check if we have valid authentication."""