38 lines
1.0 KiB
Dart
38 lines
1.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:uae_stat/infrastructure/data/p_auth_repo.dart';
|
|
|
|
class SessionCheckScreen extends StatefulWidget {
|
|
@override
|
|
_SessionCheckScreenState createState() => _SessionCheckScreenState();
|
|
}
|
|
|
|
class _SessionCheckScreenState extends State<SessionCheckScreen> {
|
|
final PAuthRepo _authRepo = PAuthRepo();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_checkSession();
|
|
}
|
|
|
|
Future<void> _checkSession() async {
|
|
await Future.delayed(Duration(seconds: 2)); // Optional splash delay
|
|
print('fetchLocallyStored');
|
|
final session = await _authRepo.fetchLocallyStored();
|
|
print('fetchLocallyStored $session');
|
|
if (session != null) {
|
|
print('myhomepage');
|
|
if (mounted) context.go('/myhomepage'); // Redirect to home
|
|
} else {
|
|
print('login');
|
|
if (mounted) context.go('/login'); // Redirect to login
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox.shrink();
|
|
}
|
|
}
|