Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ interceptor not adding headers properly when BG/FG call ] #1997

Closed
Gobmichet opened this issue Oct 16, 2023 · 1 comment
Closed

[ interceptor not adding headers properly when BG/FG call ] #1997

Gobmichet opened this issue Oct 16, 2023 · 1 comment

Comments

@Gobmichet
Copy link

Package

dio

Version

4.0.6

Operating-System

Android, iOS

Output of flutter doctor -v

[√] Flutter (Channel stable, 3.13.4, on Microsoft Windows [version 10.0.19045.3570], locale fr-FR)
    • Flutter version 3.13.4 on channel stable at C:\src\flutter\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 367f9ea16b (5 weeks ago), 2023-09-12 23:27:53 -0500
    • Engine revision 9064459a8b
    • Dart version 3.1.2
    • DevTools version 2.25.0

Dart Version

3.1.2

Steps to Reproduce

make a WS call on BG/FG :

@override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    switch (state) {
      case AppLifecycleState.resumed:
        initNewVersionPlusDialog();
        if (_isLogged && _appModel.currentUser!.accessToken != null) {
          
               // HERE MAKE THE WS CALL

        }
        break;
      default:
        // nothing
    }
  }

and with interceptor like :

class TokenInterceptor extends Interceptor {

  AppModel appModel = _mainContext.read();

  @override
  Future<void> onRequest(RequestOptions options, RequestInterceptorHandler handler) async {
    final user = appModel.currentUser;
    if (user != null) {
      final token = user.accessToken;
      options.headers["Authorization"] = token;
    } else {
      print(">> Authorization token NULL ! <<");
    }
    super.onRequest(options, handler);
  }

Expected Result

a WS call with the proper header (and that's the case 90% of time)

Actual Result

When doing a WS call on BG/FG it sometimes does not add the token in appropriate header...

What's wierd is that i can't reproduce on emulators nor on my personnal device !

But we DO have stacktraces from our server that returns error 500 no header from springboot Backends...

Even wierder : i did add the following test :
if (_isLogged && _appModel.currentUser!.accessToken != null) {

and it's done anyway missing the header :/

What am i missing ?

Is there a way to cancel such an intercepted request ?
how ?
And i also do want the login very first request to pass without this header ...

Thanks in advance.

@Gobmichet Gobmichet added h: need triage This issue needs to be categorized s: bug Something isn't working labels Oct 16, 2023
@AlexV525
Copy link
Member

  1. We don't support Dio <5 anymore.
  2. Apparently you'll need to call _mainContext.read().currentUser every time onRequest rather than a cached local variable.

Closing as invalid.

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2023
@AlexV525 AlexV525 added i: out of support and removed h: need triage This issue needs to be categorized s: bug Something isn't working labels Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants