From 7b38afc179d6c1e232e8ba1ad61553a5c7ba98bc Mon Sep 17 00:00:00 2001 From: teknium1 Date: Sun, 1 Mar 2026 20:20:30 -0800 Subject: [PATCH] fix(auth): handle session expiration and re-authentication in Nous Portal Enhanced error handling in the _model_flow_nous function to detect session expiration and prompt for re-authentication with the Nous Portal. Added logic to manage re-login attempts and provide user feedback on success or failure, improving the overall user experience during authentication issues. --- hermes_cli/main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hermes_cli/main.py b/hermes_cli/main.py index 2bc391aa..10745093 100644 --- a/hermes_cli/main.py +++ b/hermes_cli/main.py @@ -498,7 +498,21 @@ def _model_flow_nous(config, current_model=""): api_key=creds.get("api_key", ""), ) except Exception as exc: + relogin = isinstance(exc, AuthError) and exc.relogin_required msg = format_auth_error(exc) if isinstance(exc, AuthError) else str(exc) + if relogin: + print(f"Session expired: {msg}") + print("Re-authenticating with Nous Portal...\n") + try: + mock_args = argparse.Namespace( + portal_url=None, inference_url=None, client_id=None, + scope=None, no_browser=False, timeout=15.0, + ca_bundle=None, insecure=False, + ) + _login_nous(mock_args, PROVIDER_REGISTRY["nous"]) + except Exception as login_exc: + print(f"Re-login failed: {login_exc}") + return print(f"Could not fetch models: {msg}") return