From 42b8eea0ba24f4a30ba6f2f9ecea9833a43a0bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horv=C3=A1th=20Gergely?= Date: Thu, 5 Feb 2026 18:24:02 +0100 Subject: [PATCH] Improve watch sync error handling and reauthentication logic --- .../lib/helpers/api/client/kreta_client.dart | 2 +- firka/lib/helpers/watch_sync_helper.dart | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/firka/lib/helpers/api/client/kreta_client.dart b/firka/lib/helpers/api/client/kreta_client.dart index eaf39b44..96448bfe 100644 --- a/firka/lib/helpers/api/client/kreta_client.dart +++ b/firka/lib/helpers/api/client/kreta_client.dart @@ -75,7 +75,7 @@ class KretaClient { } static void _setReauthFlag() { - _setReauthFlag(); + needsReauth = true; reauthStateNotifier.value = true; } diff --git a/firka/lib/helpers/watch_sync_helper.dart b/firka/lib/helpers/watch_sync_helper.dart index 6c3fa409..5c6a415d 100644 --- a/firka/lib/helpers/watch_sync_helper.dart +++ b/firka/lib/helpers/watch_sync_helper.dart @@ -214,13 +214,31 @@ class WatchSyncHelper { debugPrint('[WatchSync] Requesting token from Watch...'); final result = await _watchChannel.invokeMethod('requestTokenFromWatch'); if (result == null) { - debugPrint('[WatchSync] No token from Watch'); + debugPrint('[WatchSync] No response from Watch'); + final currentToken = effectiveTokens.isNotEmpty ? effectiveTokens.first : null; + if (currentToken != null && + currentToken.accessToken != null && + currentToken.refreshToken != null && + currentToken.expiryDate != null && + !KretaClient.needsReauth) { + debugPrint('[WatchSync] Sending iPhone token to Watch (no response)'); + await _sendTokenToWatchInternal(currentToken); + } return; } final tokenData = result as Map; if (tokenData.containsKey('error')) { debugPrint('[WatchSync] Watch returned error: ${tokenData['error']}'); + final currentToken = effectiveTokens.isNotEmpty ? effectiveTokens.first : null; + if (currentToken != null && + currentToken.accessToken != null && + currentToken.refreshToken != null && + currentToken.expiryDate != null && + !KretaClient.needsReauth) { + debugPrint('[WatchSync] Sending iPhone token to Watch (Watch has no token)'); + await _sendTokenToWatchInternal(currentToken); + } return; }