transition 1
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user