Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
auth_service.dart
Go to the documentation of this file.
1import '/core/storage/flutter_secure_storage.dart';
2import 'package:jwt_decoder/jwt_decoder.dart';
3
4import '../constants/strings.dart';
5
8
10
11 Future<void> saveToken(String token) async {
12 await _secureStorage.save(value: token);
13 }
14
15 Future<String?> getToken() async {
16 return await _secureStorage.get();
17 }
18
19 Future<void> deleteToken() async {
20 await _secureStorage.delete();
21 }
22
23 Future<bool> isTokenValid() async {
24 final token = await getToken();
25 if (token == null) return false;
26 try {
27 final Map<String, dynamic> decodedToken = JwtDecoder.decode(token);
28 final DateTime expirationDate =
29 DateTime.fromMillisecondsSinceEpoch(decodedToken['exp'] * 1000);
30 return DateTime.now().isBefore(expirationDate);
31 } catch (e) {
32 return false;
33 }
34 }
35}
Future< bool > isTokenValid() async
Future< void > deleteToken() async
Future< String?> getToken() async
Future< void > saveToken(String token) async
final _secureStorage
static const String tokenKey
Definition strings.dart:8
final double value