transition 1

This commit is contained in:
2025-10-21 22:29:18 +02:00
parent e7ac4718dc
commit e38ab2aafa
6 changed files with 282 additions and 110 deletions
+18
View File
@@ -39,4 +39,22 @@ class TokenStorage {
await clear();
}
}
Future<bool> hasValidAccessToken() async {
final a = await access;
if (a == null || a.isEmpty) return false;
try {
final parts = a.split('.');
if (parts.length != 3) return false;
final payload = jsonDecode(
utf8.decode(base64Url.decode(base64Url.normalize(parts[1]))))
as Map<String, dynamic>;
final exp = (payload['exp'] as num?)?.toInt();
if (exp == null) return true;
final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
return now < exp - 15;
} catch (_) {
return false;
}
}
}