fix : change app architecture
feat : add some method to local storage
This commit is contained in:
42
packages/auth/lib/data/common/dio_manager.dart
Normal file
42
packages/auth/lib/data/common/dio_manager.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:auths/data/repositories/auth_repository_imp.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
import '../di/auth_di.dart';
|
||||
import 'constant.dart';
|
||||
|
||||
class DioRemoteManager {
|
||||
DioRemote? _currentClient;
|
||||
ApiEnvironment? _currentEnv;
|
||||
|
||||
DioRemote setEnvironment(ApiEnvironment env) {
|
||||
if (_currentEnv != env) {
|
||||
_currentClient = DioRemote(env.baseUrl);
|
||||
_currentEnv = env;
|
||||
}
|
||||
return _currentClient!;
|
||||
}
|
||||
|
||||
DioRemote get currentClient {
|
||||
if (_currentClient == null) {
|
||||
throw Exception('Call setEnvironment() before accessing DioRemote.');
|
||||
}
|
||||
|
||||
return _currentClient!;
|
||||
}
|
||||
|
||||
ApiEnvironment? get currentEnv => _currentEnv;
|
||||
}
|
||||
|
||||
Future<void> switchAuthEnvironment(ApiEnvironment env) async {
|
||||
final manager = diAuth.get<DioRemoteManager>();
|
||||
|
||||
final dioRemote = manager.setEnvironment(env);
|
||||
|
||||
if (diAuth.isRegistered<AuthRepositoryImpl>()) {
|
||||
await diAuth.unregister<AuthRepositoryImpl>();
|
||||
}
|
||||
|
||||
diAuth.registerLazySingleton<AuthRepositoryImpl>(
|
||||
() => AuthRepositoryImpl(dioRemote),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user