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());
|
||||
|
||||
Reference in New Issue
Block a user