mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
dio and login functions
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
import 'dart:io';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:syncrow_web/pages/auth/model/token.dart';
|
||||
import 'dart:async';
|
||||
import 'package:syncrow_web/services/api/network_exception.dart';
|
||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||
import 'package:syncrow_web/utils/snack_bar.dart';
|
||||
import 'api_links_endpoints.dart';
|
||||
|
||||
class HTTPInterceptor extends InterceptorsWrapper {
|
||||
List<String> headerExclusionList = [];
|
||||
@ -11,6 +13,7 @@ class HTTPInterceptor extends InterceptorsWrapper {
|
||||
List<String> headerExclusionListOfAddedParameters = [
|
||||
ApiEndpoints.login,
|
||||
];
|
||||
|
||||
@override
|
||||
void onResponse(Response response, ResponseInterceptorHandler handler) async {
|
||||
if (await validateResponse(response)) {
|
||||
@ -23,11 +26,11 @@ class HTTPInterceptor extends InterceptorsWrapper {
|
||||
@override
|
||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) async {
|
||||
var storage = const FlutterSecureStorage();
|
||||
// var token = await storage.read(key: Token.loginAccessTokenKey);
|
||||
// if (checkHeaderExclusionListOfAddedParameters(options.path)) {
|
||||
// options.headers.putIfAbsent(HttpHeaders.authorizationHeader, () => "Bearer $token");
|
||||
// }
|
||||
// options.headers['Authorization'] = 'Bearer ${'${token!}123'}';
|
||||
var token = await storage.read(key: Token.loginAccessTokenKey);
|
||||
if (checkHeaderExclusionListOfAddedParameters(options.path)) {
|
||||
options.headers.putIfAbsent(HttpHeaders.authorizationHeader, () => "Bearer $token");
|
||||
}
|
||||
options.headers['Authorization'] = 'Bearer ${token!}';
|
||||
super.onRequest(options, handler);
|
||||
}
|
||||
|
||||
@ -38,10 +41,10 @@ class HTTPInterceptor extends InterceptorsWrapper {
|
||||
CustomSnackBar.displaySnackBar(failure.toString());
|
||||
}
|
||||
var storage = const FlutterSecureStorage();
|
||||
// var token = await storage.read(key: Token.loginAccessTokenKey);
|
||||
// if (err.response?.statusCode == 401 && token != null) {
|
||||
// await AuthCubit.get(NavigationService.navigatorKey.currentContext!).logout();
|
||||
// }
|
||||
var token = await storage.read(key: Token.loginAccessTokenKey);
|
||||
if (err.response?.statusCode == 401 && token != null) {
|
||||
// await AuthCubit.get(NavigationService.navigatorKey.currentContext!).logout();
|
||||
}
|
||||
super.onError(err, handler);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user