Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
auth_interceptor.dart
Go to the documentation of this file.
1import 'package:dio/dio.dart';
2
3import '../constants/strings.dart';
4import '../storage/flutter_secure_storage.dart';
5
7 final Dio dio;
8
9 AuthInterceptor({required this.dio});
10
13
14 @override
16 RequestOptions options,
17 RequestInterceptorHandler handler,
18 ) async {
19 final token = await _tokenSecureStorage.get();
20 if (token != null) {
21 options.headers['Authorization'] = 'Bearer $token';
22 }
23
24 return handler.next(options);
25 }
26
27 @override
28 void onError(
29 DioException err,
30 ErrorInterceptorHandler handler,
31 ) async {
32 if (err.response?.statusCode == 401) {
34 }
35 return handler.next(err);
36 }
37
38 Future<void> _handleTokenExpiration() async {
39 await _tokenSecureStorage.delete();
40 await _sessionSecureStorage.delete();
41 }
42}
AuthInterceptor({required this.dio})
Future< void > _handleTokenExpiration() async
override void onRequest(RequestOptions options, RequestInterceptorHandler handler,) async
override void onError(DioException err, ErrorInterceptorHandler handler,) async
static const String sessionKey
Definition strings.dart:6
static const String tokenKey
Definition strings.dart:8
class EnergySavingsMeasure extends StatefulWidget options