From f7ea9f3a19875795aab37ea578eb0741a597aa65 Mon Sep 17 00:00:00 2001 From: "mr.mojtaba" Date: Sun, 18 May 2025 09:32:43 +0330 Subject: [PATCH] fix : login and route --- lib/infrastructure/service/auth_service.dart | 8 +++++--- lib/main.dart | 6 ++++++ packages/auth/lib/data/di/auth_di.dart | 1 - packages/auth/lib/data/services/auth_middelware.dart | 2 +- packages/auth/lib/presentation/pages/auth/logic.dart | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/infrastructure/service/auth_service.dart b/lib/infrastructure/service/auth_service.dart index 786ce8e..5fc3f44 100644 --- a/lib/infrastructure/service/auth_service.dart +++ b/lib/infrastructure/service/auth_service.dart @@ -1,9 +1,10 @@ import 'package:rasadyar_auth/auth.dart'; import 'package:rasadyar_auth/data/services/token_storage_service.dart'; import 'package:rasadyar_core/core.dart'; +import 'package:rasadyar_inspection/inspection.dart'; class AuthService extends GetxService { - var tokenService = diAuth.get(); + var tokenService = Get.find(); RxBool accessRes = false.obs; RxBool refAccessRes = false.obs; @override @@ -15,15 +16,16 @@ class AuthService extends GetxService { accessRes.value = (callback != null); }); - // رصد تغییرات refreshToken ever(tokenService.refreshToken, (callback) { fLog('Refresh token callback: $callback, value: ${tokenService.refreshToken.value}'); refAccessRes.value = (callback != null); }); - // بررسی اینکه هر دو مقدار دارند + everAll([accessRes, refAccessRes], (_) { if (accessRes.value && refAccessRes.value) { + + Get.offAndToNamed(InspectionRoutes.inspection); fLog('Both accessToken and refreshToken are available: accessToken=${tokenService.accessToken.value}, refreshToken=${tokenService.refreshToken.value}'); } else { fLog('One or both tokens are missing: accessToken=${tokenService.accessToken.value}, refreshToken=${tokenService.refreshToken.value}'); diff --git a/lib/main.dart b/lib/main.dart index 708bf7c..42195b2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:rasadyar_app/presentation/routes/app_pages.dart'; +import 'package:rasadyar_auth/auth.dart'; +import 'package:rasadyar_auth/data/services/token_storage_service.dart'; import 'package:rasadyar_core/core.dart'; @@ -9,6 +11,10 @@ import 'infrastructure/service/auth_service.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); await setupInjection(); + Get.put(TokenStorageService()); + var tokenService = Get.find(); + await tokenService.init(); + Get.put(AuthMiddleware()); Get.put(AuthService()); runApp(MyApp()); diff --git a/packages/auth/lib/data/di/auth_di.dart b/packages/auth/lib/data/di/auth_di.dart index 10802b1..3f4771e 100644 --- a/packages/auth/lib/data/di/auth_di.dart +++ b/packages/auth/lib/data/di/auth_di.dart @@ -16,6 +16,5 @@ Future setupAuthDI() async { diAuth.registerCachedFactory( () => AuthRepositoryImpl(dioRemote), ); - diAuth.registerLazySingleton(() => TokenStorageService()); diAuth.registerLazySingleton(() => DioErrorHandler()); } diff --git a/packages/auth/lib/data/services/auth_middelware.dart b/packages/auth/lib/data/services/auth_middelware.dart index 56c0bb4..ba907ce 100644 --- a/packages/auth/lib/data/services/auth_middelware.dart +++ b/packages/auth/lib/data/services/auth_middelware.dart @@ -6,7 +6,7 @@ import 'package:rasadyar_core/core.dart'; import '../../presentation/routes/pages.dart'; class AuthMiddleware extends GetMiddleware { - var tokenService = diAuth.get(); + var tokenService = Get.find(); @override RouteSettings? redirect(String? route) { diff --git a/packages/auth/lib/presentation/pages/auth/logic.dart b/packages/auth/lib/presentation/pages/auth/logic.dart index 3e885a7..93781d8 100644 --- a/packages/auth/lib/presentation/pages/auth/logic.dart +++ b/packages/auth/lib/presentation/pages/auth/logic.dart @@ -31,7 +31,7 @@ class AuthLogic extends GetxController { RxnString phoneNumber = RxnString(null); RxBool isLoading = false.obs; - TokenStorageService tokenStorageService = diAuth.get(); + TokenStorageService tokenStorageService = Get.find(); Rx authType = AuthType.useAndPass.obs; Rx authStatus = AuthStatus.init.obs;