Add offline meal journal and secure sync

This commit is contained in:
Hamza-Ayed
2026-10-04 02:13:23 +03:00
parent d892e3d981
commit 27fc2d5eb1
12 changed files with 936 additions and 23 deletions
+17
View File
@@ -119,6 +119,23 @@ class AuthService {
return response;
}
Future<http.Response> authenticatedGet(Uri uri) async {
_requireApi();
_accessToken ??= await _storage.read(key: _accessKey);
if (_accessToken == null && !await _refreshSession()) {
throw const AuthException('سجّل الدخول لمزامنة بياناتك.');
}
var response = await _client
.get(uri, headers: _bearerHeaders(_accessToken!))
.timeout(const Duration(seconds: 30));
if (response.statusCode == 401 && await _refreshSession()) {
response = await _client
.get(uri, headers: _bearerHeaders(_accessToken!))
.timeout(const Duration(seconds: 30));
}
return response;
}
Future<bool> _refreshSession() async {
final activeRefresh = _refreshing;
if (activeRefresh != null) return activeRefresh;