You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@OverRide
Future onResponse(Response response, ResponseInterceptorHandler handler) {
if (response.headers.value("verifyToken") != null) {
//if the header is present, then compare it with the Shared Prefs key
// SharedPreferences prefs = await SharedPreferences.getInstance();
// var verifyToken = prefs.get("VerifyToken");
// // if the value is the same as the header, continue with the request
// if (options.headers.value("verifyToken") == verifyToken) {
// return options;
// }
}
if (response.data is Map) {
log(jsonEncode(response.data), name: "Response");
} else if (response.data is String) {
log(response.data, name: "Response");
}
super.onResponse(response, handler);
return Future.value(response);
// return handler.next(response);
Package
dio
Version
dio: ^5.7.0
Operating-System
Android, iOS
Adapter
Default Dio
Output of
flutter doctor -v
Dart Version
3.5.3
Steps to Reproduce
class AppInterceptors extends QueuedInterceptor {
// class AppInterceptors extends Interceptor {
late final Dio? _dio;
// final AuthRepo authRepo = getIt();
AppInterceptors(this._dio);
@OverRide
// ignore: avoid_void_async
void onRequest(
RequestOptions options, RequestInterceptorHandler handler) async {
String fullUrl = options.baseUrl + options.path;
// If the request has query parameters, append them
if (options.queryParameters.isNotEmpty) {
String queryString = Uri(queryParameters: options.queryParameters).query;
fullUrl += '?' + queryString;
}
if (!options.headers.containsKey("Authorization")) {
final session = getIt();
final String? token = await session.getAccessToken();
final String? xMemberId = await session.getMemberId();
final String? xUserId = session.user?.id != null ? session.user?.id : "";
}
@OverRide
Future onResponse(Response response, ResponseInterceptorHandler handler) {
if (response.headers.value("verifyToken") != null) {
//if the header is present, then compare it with the Shared Prefs key
// SharedPreferences prefs = await SharedPreferences.getInstance();
// var verifyToken = prefs.get("VerifyToken");
}
bool _isRefreshing = false;
Completer? _refreshCompleter;
@OverRide
Future onError(DioException err, ErrorInterceptorHandler handler) async {
if (err.response != null && err.response?.statusCode == 401) {
final SessionService session = getIt();
}
/* Future<Map<String, dynamic>?> _refreshToken() async {
final SessionService session = getIt();
final NavigationService navigationService = getIt();
final String? refreshToken = await session.getRefreshToken();
}*/
Future<Response?> _refreshToken(ErrorInterceptorHandler handler) async {
final SessionService session = getIt();
final NavigationService navigationService = getIt();
try {
final String? refreshToken = await session.getRefreshToken();
final response = await _dio?.patch(
"${Constants.devAuthBaseUrl}refresh-token",
data: {"refreshToken": refreshToken});
debugPrint("refreshToken######");
if (response?.statusCode == 200) {
await session.saveSession(session.user!.copyWith(
refreshToken: response?.data["data"]["refreshToken"],
token: response?.data["data"]["token"]));
return response;
}
else{
navigationService.currentContext?.read().logout(isUnauthorised: true);
}
}
Expected Result
final response = await _dio?.patch(
"${Constants.devAuthBaseUrl}refresh-token",
data: {"refreshToken": refreshToken});
Actual Result
final response = await _dio?.patch(
"${Constants.devAuthBaseUrl}refresh-token",
data: {"refreshToken": refreshToken});
The text was updated successfully, but these errors were encountered: