Add offline meal journal and secure sync
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user