Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/reflex-hosting-cli/src/reflex_cli/utils/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
5 changes: 3 additions & 2 deletions packages/reflex-hosting-cli/src/reflex_cli/v2/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions reflex/reflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
51 changes: 25 additions & 26 deletions reflex/utils/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
}


Expand Down
Loading