From 00d366683f0cc42d354479bc8b756c8723c9e1a5 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Wed, 20 May 2026 15:27:02 -0700 Subject: [PATCH 1/4] Display ToS / privacy warning on console with logging in --- .../src/reflex_cli/utils/hosting.py | 5 +- .../src/reflex_cli/v2/cli.py | 5 +- reflex/reflex.py | 7 +-- reflex/utils/telemetry.py | 52 +++++++++---------- 4 files changed, 36 insertions(+), 33 deletions(-) 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..056920777ce 100644 --- a/packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py +++ b/packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py @@ -1984,7 +1984,10 @@ 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} ...") + console.print( + f"Opening {auth_url} ... By connecting your account, you agree to " + "Reflex Cloud [Terms of Service] and [Privacy Policy]." + ) if not is_valid_url(constants.Hosting.HOSTING_SERVICE_UI): console.error( 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..58450e7b596 100644 --- a/reflex/utils/telemetry.py +++ b/reflex/utils/telemetry.py @@ -12,7 +12,7 @@ from contextlib import suppress from datetime import datetime, timezone from pathlib import Path -from typing import Any, TypedDict, cast +from typing import Any, NotRequired, TypedDict, cast from reflex_base import constants from reflex_base.config import get_config @@ -232,7 +232,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 +264,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, } From 92e9a3deede8574d90a8e7cbb3c72260798e7dd2 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Wed, 20 May 2026 16:02:21 -0700 Subject: [PATCH 2/4] Update packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 056920777ce..e92e5bcdb36 100644 --- a/packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py +++ b/packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py @@ -1986,7 +1986,8 @@ def authenticate_on_browser() -> tuple[str, dict[str, Any]]: console.print( f"Opening {auth_url} ... By connecting your account, you agree to " - "Reflex Cloud [Terms of Service] and [Privacy Policy]." + "Reflex Cloud [Terms of Service] and [Privacy Policy].", + markup=False, ) if not is_valid_url(constants.Hosting.HOSTING_SERVICE_UI): From 2aead3dea02a044a238ffeb19120ddb1710ec6ec Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Wed, 20 May 2026 16:03:36 -0700 Subject: [PATCH 3/4] Reorder console print statement for auth URL --- .../src/reflex_cli/utils/hosting.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 e92e5bcdb36..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,18 +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} ... By connecting your account, you agree to " - "Reflex Cloud [Terms of Service] and [Privacy Policy].", - markup=False, - ) - 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." From be98ff748c228213aec9577bd739d63a1c83111e Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Wed, 20 May 2026 16:23:35 -0700 Subject: [PATCH 4/4] fix: import NotRequired from typing_extensions for py3.10 compat `typing.NotRequired` was added in Python 3.11; the project still supports 3.10. Co-Authored-By: Claude Opus 4.7 (1M context) --- reflex/utils/telemetry.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reflex/utils/telemetry.py b/reflex/utils/telemetry.py index 58450e7b596..c2866a127c0 100644 --- a/reflex/utils/telemetry.py +++ b/reflex/utils/telemetry.py @@ -12,13 +12,14 @@ from contextlib import suppress from datetime import datetime, timezone from pathlib import Path -from typing import Any, NotRequired, TypedDict, cast +from typing import Any, TypedDict, cast from reflex_base import constants from reflex_base.config import get_config 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