Fix sync TUI freeze by completing auth before starting dashboard

This commit is contained in:
Bendt
2025-12-19 15:50:23 -05:00
parent 560bc1d3bd
commit aaabd83fc7
2 changed files with 82 additions and 0 deletions

View File

@@ -715,6 +715,24 @@ def sync(
else:
# Default: Launch interactive TUI dashboard
from .sync_dashboard import run_dashboard_sync
from src.services.microsoft_graph.auth import has_valid_cached_token
# Check if we need to authenticate before starting the TUI
# This prevents the TUI from appearing to freeze during device flow auth
if not demo:
scopes = [
"https://graph.microsoft.com/Calendars.Read",
"https://graph.microsoft.com/Mail.ReadWrite",
]
if not has_valid_cached_token(scopes):
click.echo("Authentication required. Please complete the login flow...")
try:
# This will trigger the device flow auth in the console
get_access_token(scopes)
click.echo("Authentication successful! Starting dashboard...")
except Exception as e:
click.echo(f"Authentication failed: {e}")
return
sync_config = {
"org": org,
@@ -936,6 +954,27 @@ def status():
def interactive(org, vdir, notify, dry_run, demo):
"""Launch interactive TUI dashboard for sync operations."""
from .sync_dashboard import run_dashboard_sync
from src.services.microsoft_graph.auth import (
has_valid_cached_token,
get_access_token,
)
# Check if we need to authenticate before starting the TUI
# This prevents the TUI from appearing to freeze during device flow auth
if not demo:
scopes = [
"https://graph.microsoft.com/Calendars.Read",
"https://graph.microsoft.com/Mail.ReadWrite",
]
if not has_valid_cached_token(scopes):
click.echo("Authentication required. Please complete the login flow...")
try:
# This will trigger the device flow auth in the console
get_access_token(scopes)
click.echo("Authentication successful! Starting dashboard...")
except Exception as e:
click.echo(f"Authentication failed: {e}")
return
sync_config = {
"org": org,