Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
auth_service.dart
Go to the documentation of this file.
1import 'package:jwt_decoder/jwt_decoder.dart';
2
3import '../constants/strings.dart';
4import 'secure_storage_service.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
27 try {
28 final Map<String, dynamic> decodedToken = JwtDecoder.decode(token);
29 final DateTime expirationDate = 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 SecureStorageService _secureStorage
static const String tokenKey
Definition strings.dart:8
class Partner String