diff --git a/packages/auth/lib/data/di/auth_di.dart b/packages/auth/lib/data/di/auth_di.dart index cc89573..5accae7 100644 --- a/packages/auth/lib/data/di/auth_di.dart +++ b/packages/auth/lib/data/di/auth_di.dart @@ -16,9 +16,16 @@ Future setupAuthDI() async { final dioRemote = diAuth.get(); await dioRemote.init(); - diAuth.registerCachedFactory( - () => AuthRepositoryImpl(dioRemote), - ); - + diAuth.registerSingleton(AuthRepositoryImpl(dioRemote)); diAuth.registerLazySingleton(() => DioErrorHandler()); } + +Future newSetupAuthDI(String newUrl) async { + diAuth.registerLazySingleton(() => DioRemote(baseUrl: newUrl),instanceName: 'newRemote'); + final dioRemote = diAuth.get(instanceName: 'newRemote'); + await dioRemote.init(); + diAuth.registerSingleton( + AuthRepositoryImpl(dioRemote), + instanceName: 'newUrl', + ); +} diff --git a/packages/auth/lib/presentation/pages/auth/logic.dart b/packages/auth/lib/presentation/pages/auth/logic.dart index 31c6607..0c6093a 100644 --- a/packages/auth/lib/presentation/pages/auth/logic.dart +++ b/packages/auth/lib/presentation/pages/auth/logic.dart @@ -135,10 +135,10 @@ class AuthLogic extends GetxController { Future submitLoginForm2() async { if (!_isFormValid()) return; - + AuthRepositoryImpl authTmp = diAuth.get(instanceName: 'newUrl'); isLoading.value = true; await safeCall( - call: () => authRepository.login( + call: () => authTmp.login( authRequest: { "username": phoneNumberController.value.text, "password": passwordController.value.text, @@ -165,10 +165,7 @@ class AuthLogic extends GetxController { call: () async => await authRepository.getUserInfo(value), onSuccess: (result) async { if (result != null) { - diAuth.registerSingleton( - DioRemote(baseUrl: result.backend), - instanceName: 'newDioRemote', - ); + await newSetupAuthDI(result.backend ?? ''); await tokenStorageService.saveApiKey(result.apiKey ?? ''); await tokenStorageService.saveBaseUrl(result.backend ?? ''); } diff --git a/packages/auth/lib/presentation/widget/captcha/logic.dart b/packages/auth/lib/presentation/widget/captcha/logic.dart index a24052a..ef21e40 100644 --- a/packages/auth/lib/presentation/widget/captcha/logic.dart +++ b/packages/auth/lib/presentation/widget/captcha/logic.dart @@ -30,7 +30,7 @@ class CaptchaWidgetLogic extends GetxController with StateMixin