2

I have many API calls to the server, in many of them if I get a 401 response then I should forward the user to the login screen to refresh the token that I used for authorization.

http.post(
       URL,
       body: jsonEncode(loginHttpBody),)
    .then((response) {
      if (response.statusCode == 401) {
        Navigator.pushNamed(context, LoginScreen.id);
      }
    });

I need a way to make a global interceptor to check if any of the HTTP requests have 401 status to forward the user to log in screen, not writing this code in all of my HTTP requests. The package that I use for my HTTP request is http

Ali Abbas
  • 1,415
  • 12
  • 19

0 Answers0