Files
Stocky/lib/Pages/controllers/SplashScreenController.dart

33 lines
761 B
Dart

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');
}
}
}