setting up a pipeline to create account or log in on setup

This commit is contained in:
kai
2025-12-04 21:03:11 -05:00
parent 7bc4f6f835
commit d32b2576b0
2 changed files with 34 additions and 1 deletions

View File

@@ -37,7 +37,14 @@ class LoginCommand(BaseCommand):
receiver = AuthReceiver()
try:
port = receiver.start()
target_url = f"{ENDPOINTS['cli_login']}?redirect_port={port}"
# Construct the full redirect_to URL using constants
from tito.core.auth import LOCAL_SERVER_HOST, AUTH_CALLBACK_PATH
redirect_to_url = f"http://{LOCAL_SERVER_HOST}:{port}{AUTH_CALLBACK_PATH}"
# Update target_url to include the explicit redirect_to parameter
target_url = f"{ENDPOINTS['cli_login']}?redirect_to={redirect_to_url}&redirect_port={port}"
self.console.print(f"Opening browser to: [cyan]{target_url}[/cyan]")
self.console.print("Waiting for authentication...")
webbrowser.open(target_url)

View File

@@ -25,6 +25,7 @@ from rich.progress import Progress, SpinnerColumn, TextColumn
from rich import box
from .base import BaseCommand
from .login import LoginCommand
from ..core.console import get_console
def _print_file_update(console, file_path: Path) -> None:
@@ -384,6 +385,28 @@ class SetupCommand(BaseCommand):
self.console.print("\n[green]Welcome to the community! 🎉[/green]")
else:
self.console.print("[dim]No problem! You can join anytime at tinytorch.ai/join[/dim]")
def prompt_community_login(self) -> None:
"""Prompt user to log in to the TinyTorch community via CLI."""
self.console.print()
if Confirm.ask("[bold]Would you like to connect your TinyTorch CLI to the community now (for leaderboard submissions, progress syncing, etc.)?[/bold]", default=True):
self.console.print("\n[cyan]Starting community login process...[/cyan]")
login_cmd = LoginCommand(self.config)
# Create a dummy Namespace for login command arguments
login_args = Namespace(force=False)
try:
login_result = login_cmd.run(login_args)
if login_result == 0:
self.console.print("[green]✅ Successfully connected to the TinyTorch community![/green]")
else:
self.console.print("[yellow]⚠️ Community connection failed or was cancelled. You can try again later with 'tito community login'.[/yellow]")
except Exception as e:
self.console.print(f"[yellow]⚠️ Error during login: {e}[/yellow]")
else:
self.console.print("[dim]You can connect to the community anytime with 'tito community login'.[/dim]")
def run(self, args: Namespace) -> int:
"""Execute the setup command."""
@@ -431,6 +454,9 @@ class SetupCommand(BaseCommand):
# Prompt to join community
self.prompt_community_registration()
# Prompt to login to CLI
self.prompt_community_login()
return 0