http_interceptor icon indicating copy to clipboard operation
http_interceptor copied to clipboard

refreshToken called multiple times

Open heshesh2010 opened this issue 2 years ago • 2 comments

Hi ,

I call many api at same time , but I see when token expire I got 401 , so it's goes to refresh token and retry , but in the same time the other api request in queue gets called and try to refresh the token again , so refresh api return 422 error . so it should only calling only once .

so how to pause the all other apis request until the token it gets refreshed ?

using http_interceptor: ^2.0.0-beta.7

`

  @override
  Future<bool> shouldAttemptRetryOnResponse(BaseResponse response) async {
    if (response.statusCode == 401) {
      print('Retrying request...');
      // final cache = await SharedPreferences.getInstance();

      // cache.setString(kOWApiToken, kOpenWeatherApiKey);

      AuthController authController = Get.put(AuthController());
      authController.refreshToken();

      return true;
    }

    return false;
  }

`

heshesh2010 avatar Aug 27 '23 22:08 heshesh2010

Hi, this PR https://github.com/CodingAleCR/http_interceptor/pull/96 seems to solve your problem. Unfortunately, it does not seem to be abandoned.

PKeviin avatar Nov 21 '23 12:11 PKeviin