Начальный коммит
This commit is contained in:
32
lib/Pages/controllers/SplashScreenController.dart
Normal file
32
lib/Pages/controllers/SplashScreenController.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'package:Stocky/services/local/StorageService.dart';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class SplashScreenController extends GetxController {
|
||||
late Future<bool> _authCheck;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
_authCheck = _checkAuthentication();
|
||||
}
|
||||
|
||||
Future<bool> _checkAuthentication() async {
|
||||
final LocalStorageService settings = Get.find<LocalStorageService>();
|
||||
final accessToken = settings.getAccessToken();
|
||||
if (accessToken != null && accessToken.isNotEmpty) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> navigateBasedOnAuth() async {
|
||||
final isAuthenticated = await _authCheck;
|
||||
|
||||
if (isAuthenticated) {
|
||||
Get.offAllNamed('/home');
|
||||
} else {
|
||||
Get.offAllNamed('/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user