Geschlecht und Merkmal
This commit is contained in:
@@ -11,7 +11,12 @@ class SplashScreen extends ConsumerStatefulWidget {
|
||||
ConsumerState<SplashScreen> createState() => _SplashState();
|
||||
}
|
||||
|
||||
class _SplashState extends ConsumerState<SplashScreen> {
|
||||
class _SplashState extends ConsumerState<SplashScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _ac = AnimationController(
|
||||
vsync: this, duration: const Duration(milliseconds: 600))
|
||||
..forward();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -20,24 +25,16 @@ class _SplashState extends ConsumerState<SplashScreen> {
|
||||
|
||||
Future<void> _boot() async {
|
||||
final tokens = ref.read(tokenStorageProvider);
|
||||
// 1) Versuch: vorhandenes Access prüfen
|
||||
final access = await tokens.access;
|
||||
final isValid = _isJwtValid(access);
|
||||
|
||||
if (!isValid) {
|
||||
// 2) Refresh versuchen
|
||||
var authed = _isJwtValid(access);
|
||||
if (!authed) {
|
||||
await tokens.refreshAccess();
|
||||
authed = _isJwtValid(await tokens.access);
|
||||
}
|
||||
|
||||
final access2 = await tokens.access;
|
||||
final authed = _isJwtValid(access2);
|
||||
|
||||
if (!mounted) return;
|
||||
if (authed) {
|
||||
context.go('/igel');
|
||||
} else {
|
||||
context.go('/login');
|
||||
}
|
||||
await Future.delayed(
|
||||
const Duration(milliseconds: 300)); // kleines Fade-Finish
|
||||
context.go(authed ? '/igel' : '/login');
|
||||
}
|
||||
|
||||
bool _isJwtValid(String? jwt) {
|
||||
@@ -49,18 +46,36 @@ class _SplashState extends ConsumerState<SplashScreen> {
|
||||
utf8.decode(base64Url.decode(base64Url.normalize(parts[1]))))
|
||||
as Map<String, dynamic>;
|
||||
final exp = (payload['exp'] as num?)?.toInt();
|
||||
if (exp == null) return true; // kein exp => als gültig betrachten
|
||||
final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
return now < exp - 15; // kleine Toleranz
|
||||
return exp == null ? true : now < exp - 15;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ac.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
final t = CurvedAnimation(parent: _ac, curve: Curves.easeOut);
|
||||
return Scaffold(
|
||||
body: FadeTransition(
|
||||
opacity: t,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: const [
|
||||
Icon(Icons.pets, size: 96),
|
||||
SizedBox(height: 12),
|
||||
CircularProgressIndicator(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user