fix : login and route
This commit is contained in:
@@ -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<TokenStorageService>();
|
||||
var tokenService = Get.find<TokenStorageService>();
|
||||
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}');
|
||||
|
||||
@@ -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<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await setupInjection();
|
||||
Get.put(TokenStorageService());
|
||||
var tokenService = Get.find<TokenStorageService>();
|
||||
await tokenService.init();
|
||||
Get.put(AuthMiddleware());
|
||||
Get.put(AuthService());
|
||||
|
||||
runApp(MyApp());
|
||||
|
||||
@@ -16,6 +16,5 @@ Future<void> setupAuthDI() async {
|
||||
diAuth.registerCachedFactory<AuthRepositoryImpl>(
|
||||
() => AuthRepositoryImpl(dioRemote),
|
||||
);
|
||||
diAuth.registerLazySingleton<TokenStorageService>(() => TokenStorageService());
|
||||
diAuth.registerLazySingleton<DioErrorHandler>(() => DioErrorHandler());
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import 'package:rasadyar_core/core.dart';
|
||||
import '../../presentation/routes/pages.dart';
|
||||
|
||||
class AuthMiddleware extends GetMiddleware {
|
||||
var tokenService = diAuth.get<TokenStorageService>();
|
||||
var tokenService = Get.find<TokenStorageService>();
|
||||
|
||||
@override
|
||||
RouteSettings? redirect(String? route) {
|
||||
|
||||
@@ -31,7 +31,7 @@ class AuthLogic extends GetxController {
|
||||
|
||||
RxnString phoneNumber = RxnString(null);
|
||||
RxBool isLoading = false.obs;
|
||||
TokenStorageService tokenStorageService = diAuth.get<TokenStorageService>();
|
||||
TokenStorageService tokenStorageService = Get.find<TokenStorageService>();
|
||||
|
||||
Rx<AuthType> authType = AuthType.useAndPass.obs;
|
||||
Rx<AuthStatus> authStatus = AuthStatus.init.obs;
|
||||
|
||||
Reference in New Issue
Block a user