Skip to content

Commit f6ef005

Browse files
masenfgreptile-apps[bot]claude
authored
Display ToS / privacy warning on console with logging in (#6547)
* Display ToS / privacy warning on console with logging in * 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> * Reorder console print statement for auth URL * 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) <noreply@anthropic.com> --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent bf2deed commit f6ef005

4 files changed

Lines changed: 38 additions & 33 deletions

File tree

packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,14 +1984,18 @@ def authenticate_on_browser() -> tuple[str, dict[str, Any]]:
19841984
constants.Hosting.HOSTING_SERVICE_UI, f"/cli/login?request_id={request_id}"
19851985
)
19861986

1987-
console.print(f"Opening {auth_url} ...")
1988-
19891987
if not is_valid_url(constants.Hosting.HOSTING_SERVICE_UI):
19901988
console.error(
19911989
f"Invalid hosting URL: {constants.Hosting.HOSTING_SERVICE_UI}. Ensure the URL is in the correct format and includes a valid scheme"
19921990
)
19931991
raise click.exceptions.Exit(1)
19941992

1993+
console.print(
1994+
f"Opening {auth_url} ... By connecting your account, you agree to "
1995+
"Reflex Cloud [Terms of Service] and [Privacy Policy].",
1996+
markup=False,
1997+
)
1998+
19951999
if not webbrowser.open(auth_url):
19962000
console.warn(
19972001
f"Unable to automatically open the browser. Please go to {auth_url} to authenticate."

packages/reflex-hosting-cli/src/reflex_cli/v2/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def login(
2828
loglevel: The log level to use.
2929
3030
Returns:
31-
Information about the logged in user.
31+
Information about the newly logged in user or empty dict if already
32+
logged in.
3233
3334
Raises:
3435
SystemExit: If the command fails.
@@ -42,7 +43,7 @@ def login(
4243
access_token, validated_info = hosting.authenticated_token()
4344
if access_token:
4445
console.print("You already logged in.")
45-
return validated_info
46+
return {}
4647

4748
# If not already logged in, open a browser window/tab to the login page.
4849
access_token, validated_info = hosting.authenticate_on_browser()

reflex/reflex.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,12 +598,13 @@ def login():
598598

599599
check_version()
600600

601-
validated_info = hosting_cli.login()
602-
if validated_info is not None:
601+
if (validated_info := hosting_cli.login()) and (
602+
user_uuid := validated_info.get("user_id")
603+
):
603604
_skip_compile() # Allow running outside of an app dir
604605
from reflex.utils import telemetry
605606

606-
telemetry.send("login", user_uuid=validated_info.get("user_id"))
607+
telemetry.send("login", user_uuid=user_uuid)
607608

608609

609610
@cli.command()

reflex/utils/telemetry.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from reflex_base.environment import environment
2020
from reflex_base.utils.decorator import once, once_unless_none
2121
from reflex_base.utils.exceptions import ReflexError
22+
from typing_extensions import NotRequired
2223

2324
from reflex.utils import console, processes
2425
from reflex.utils.js_runtimes import get_bun_version, get_node_version
@@ -232,7 +233,7 @@ class _Properties(TypedDict):
232233
"""Properties type for telemetry."""
233234

234235
distinct_id: int
235-
distinct_app_id: int
236+
distinct_app_id: NotRequired[int]
236237
user_os: str
237238
user_os_detail: str
238239
reflex_version: str
@@ -264,36 +265,34 @@ def _get_event_defaults() -> _DefaultEvent | None:
264265
Returns:
265266
The default event data.
266267
"""
267-
installation_id = ensure_reflex_installation_id()
268-
project_hash = get_project_hash(raise_on_fail=_raise_on_missing_project_hash())
269-
270-
if installation_id is None or project_hash is None:
271-
console.debug(
272-
f"Could not get installation_id or project_hash: {installation_id}, {project_hash}"
273-
)
268+
if (installation_id := ensure_reflex_installation_id()) is None:
269+
console.debug("Could not get installation_id")
274270
return None
275-
276271
cpuinfo = get_cpu_info()
272+
properties: _Properties = {
273+
"distinct_id": installation_id,
274+
"user_os": get_os(),
275+
"user_os_detail": get_detailed_platform_str(),
276+
"reflex_version": get_reflex_version(),
277+
"python_version": get_python_version(),
278+
"node_version": (
279+
str(node_version) if (node_version := get_node_version()) else None
280+
),
281+
"bun_version": (
282+
str(bun_version) if (bun_version := get_bun_version()) else None
283+
),
284+
"reflex_enterprise_version": get_reflex_enterprise_version(),
285+
"cpu_count": get_cpu_count(),
286+
"cpu_info": dataclasses.asdict(cpuinfo) if cpuinfo else {},
287+
}
288+
if (
289+
project_hash := get_project_hash(raise_on_fail=_raise_on_missing_project_hash())
290+
) is not None:
291+
properties["distinct_app_id"] = project_hash
277292

278293
return {
279294
"api_key": "phc_JoMo0fOyi0GQAooY3UyO9k0hebGkMyFJrrCw1Gt5SGb",
280-
"properties": {
281-
"distinct_id": installation_id,
282-
"distinct_app_id": project_hash,
283-
"user_os": get_os(),
284-
"user_os_detail": get_detailed_platform_str(),
285-
"reflex_version": get_reflex_version(),
286-
"python_version": get_python_version(),
287-
"node_version": (
288-
str(node_version) if (node_version := get_node_version()) else None
289-
),
290-
"bun_version": (
291-
str(bun_version) if (bun_version := get_bun_version()) else None
292-
),
293-
"reflex_enterprise_version": get_reflex_enterprise_version(),
294-
"cpu_count": get_cpu_count(),
295-
"cpu_info": dataclasses.asdict(cpuinfo) if cpuinfo else {},
296-
},
295+
"properties": properties,
297296
}
298297

299298

0 commit comments

Comments
 (0)