Load server configuration
This commit is contained in:
@ -2,8 +2,11 @@ import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:moneymgr_mobile/services/api/api_token.dart';
|
||||
import 'package:moneymgr_mobile/services/storage/prefs.dart';
|
||||
import 'package:moneymgr_mobile/services/storage/secure_storage.dart';
|
||||
import 'package:moneymgr_mobile/utils/string_utils.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
part 'api_client.g.dart';
|
||||
|
||||
@ -14,8 +17,9 @@ const apiTokenHeader = "X-Auth-Token";
|
||||
class ApiClient {
|
||||
final ApiToken token;
|
||||
final Dio client;
|
||||
final SharedPreferencesWithCache prefs;
|
||||
|
||||
ApiClient({required this.token})
|
||||
ApiClient({required this.token, required this.prefs})
|
||||
: client = Dio(BaseOptions(baseUrl: token.apiUrl));
|
||||
|
||||
/// Get Dio instance
|
||||
@ -54,19 +58,14 @@ class ApiClient {
|
||||
/// The API client is kept alive to follow dio's recommendation to use the same
|
||||
/// client instance for the entire app.
|
||||
@riverpod
|
||||
ApiClient apiService(Ref ref) {
|
||||
/*final token = ref.watch(currentAuthStateProvider);
|
||||
ApiClient? apiService(Ref ref) {
|
||||
final storage = ref.watch(secureStorageProvider);
|
||||
final prefs = ref.watch(prefsProvider);
|
||||
|
||||
final ApiClient client;
|
||||
final t = storage.value?.token();
|
||||
if (t == null || prefs.value == null) return null;
|
||||
|
||||
const mock = bool.fromEnvironment('MOCK_API', defaultValue: false);
|
||||
client = switch (mock) {
|
||||
true =>
|
||||
token != null ? MockedApiClient.withToken(token) : MockedApiClient(),
|
||||
false => token != null ? ApiClient.withToken(token) : ApiClient(),
|
||||
};
|
||||
ref.keepAlive();
|
||||
|
||||
return client;*/
|
||||
throw Exception("TODO"); // TODO
|
||||
return ApiClient(token: t, prefs: prefs.value!);
|
||||
}
|
||||
|
Reference in New Issue
Block a user