diff --git a/packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py b/packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py index 98c0553c8d5..ef8db9f4ba1 100644 --- a/packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py +++ b/packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py @@ -1984,14 +1984,18 @@ def authenticate_on_browser() -> tuple[str, dict[str, Any]]: constants.Hosting.HOSTING_SERVICE_UI, f"/cli/login?request_id={request_id}" ) - console.print(f"Opening {auth_url} ...") - if not is_valid_url(constants.Hosting.HOSTING_SERVICE_UI): console.error( f"Invalid hosting URL: {constants.Hosting.HOSTING_SERVICE_UI}. Ensure the URL is in the correct format and includes a valid scheme" ) raise click.exceptions.Exit(1) + console.print( + f"Opening {auth_url} ... By connecting your account, you agree to " + "Reflex Cloud [Terms of Service] and [Privacy Policy].", + markup=False, + ) + if not webbrowser.open(auth_url): console.warn( f"Unable to automatically open the browser. Please go to {auth_url} to authenticate." diff --git a/packages/reflex-hosting-cli/src/reflex_cli/v2/cli.py b/packages/reflex-hosting-cli/src/reflex_cli/v2/cli.py index fe14265d458..4ae50f52eb4 100644 --- a/packages/reflex-hosting-cli/src/reflex_cli/v2/cli.py +++ b/packages/reflex-hosting-cli/src/reflex_cli/v2/cli.py @@ -28,7 +28,8 @@ def login( loglevel: The log level to use. Returns: - Information about the logged in user. + Information about the newly logged in user or empty dict if already + logged in. Raises: SystemExit: If the command fails. @@ -42,7 +43,7 @@ def login( access_token, validated_info = hosting.authenticated_token() if access_token: console.print("You already logged in.") - return validated_info + return {} # If not already logged in, open a browser window/tab to the login page. access_token, validated_info = hosting.authenticate_on_browser() diff --git a/reflex/reflex.py b/reflex/reflex.py index 7fd181f8568..daa63ba4187 100644 --- a/reflex/reflex.py +++ b/reflex/reflex.py @@ -598,12 +598,13 @@ def login(): check_version() - validated_info = hosting_cli.login() - if validated_info is not None: + if (validated_info := hosting_cli.login()) and ( + user_uuid := validated_info.get("user_id") + ): _skip_compile() # Allow running outside of an app dir from reflex.utils import telemetry - telemetry.send("login", user_uuid=validated_info.get("user_id")) + telemetry.send("login", user_uuid=user_uuid) @cli.command() diff --git a/reflex/utils/telemetry.py b/reflex/utils/telemetry.py index ebe88f82a71..c2866a127c0 100644 --- a/reflex/utils/telemetry.py +++ b/reflex/utils/telemetry.py @@ -19,6 +19,7 @@ from reflex_base.environment import environment from reflex_base.utils.decorator import once, once_unless_none from reflex_base.utils.exceptions import ReflexError +from typing_extensions import NotRequired from reflex.utils import console, processes from reflex.utils.js_runtimes import get_bun_version, get_node_version @@ -232,7 +233,7 @@ class _Properties(TypedDict): """Properties type for telemetry.""" distinct_id: int - distinct_app_id: int + distinct_app_id: NotRequired[int] user_os: str user_os_detail: str reflex_version: str @@ -264,36 +265,34 @@ def _get_event_defaults() -> _DefaultEvent | None: Returns: The default event data. """ - installation_id = ensure_reflex_installation_id() - project_hash = get_project_hash(raise_on_fail=_raise_on_missing_project_hash()) - - if installation_id is None or project_hash is None: - console.debug( - f"Could not get installation_id or project_hash: {installation_id}, {project_hash}" - ) + if (installation_id := ensure_reflex_installation_id()) is None: + console.debug("Could not get installation_id") return None - cpuinfo = get_cpu_info() + properties: _Properties = { + "distinct_id": installation_id, + "user_os": get_os(), + "user_os_detail": get_detailed_platform_str(), + "reflex_version": get_reflex_version(), + "python_version": get_python_version(), + "node_version": ( + str(node_version) if (node_version := get_node_version()) else None + ), + "bun_version": ( + str(bun_version) if (bun_version := get_bun_version()) else None + ), + "reflex_enterprise_version": get_reflex_enterprise_version(), + "cpu_count": get_cpu_count(), + "cpu_info": dataclasses.asdict(cpuinfo) if cpuinfo else {}, + } + if ( + project_hash := get_project_hash(raise_on_fail=_raise_on_missing_project_hash()) + ) is not None: + properties["distinct_app_id"] = project_hash return { "api_key": "phc_JoMo0fOyi0GQAooY3UyO9k0hebGkMyFJrrCw1Gt5SGb", - "properties": { - "distinct_id": installation_id, - "distinct_app_id": project_hash, - "user_os": get_os(), - "user_os_detail": get_detailed_platform_str(), - "reflex_version": get_reflex_version(), - "python_version": get_python_version(), - "node_version": ( - str(node_version) if (node_version := get_node_version()) else None - ), - "bun_version": ( - str(bun_version) if (bun_version := get_bun_version()) else None - ), - "reflex_enterprise_version": get_reflex_enterprise_version(), - "cpu_count": get_cpu_count(), - "cpu_info": dataclasses.asdict(cpuinfo) if cpuinfo else {}, - }, + "properties": properties, }