From aa8b3d5e165b15f636554cb8a39146b242db719d 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 eaf39b4..96448bf 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 6c3fa40..5c6a415 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; }