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

[Auth] Fetch Auth Session fail after relogin #1438

Closed
3 of 9 tasks
jack24254029 opened this issue Mar 7, 2022 · 52 comments
Closed
3 of 9 tasks

[Auth] Fetch Auth Session fail after relogin #1438

jack24254029 opened this issue Mar 7, 2022 · 52 comments
Assignees
Labels
auth Issues related to the Auth Category bug Something is not working; the issue has reproducible steps and has been reproduced fixed-in-release-candidate Issues that have been addressed in the current release-candidate branch pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days.

Comments

@jack24254029
Copy link

jack24254029 commented Mar 7, 2022

Description

When call fetchAuthSession fail first time, the app will call signout and signin then call fetchAuthSession again, but it still fail.

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Storage

Steps to Reproduce

User DON'T refresh token after a week or more maybe can reproduce this behavior.

Screenshots

No response

Platforms

  • iOS
  • Android

Environment

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.2, on macOS 12.1 21C52 darwin-x64, locale zh-Hant-TW)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.64.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!

Dependencies

Dart SDK 2.16.1
Flutter SDK 2.10.2
gp926_flutter 1.0.0+1

dependencies:
- amplify_auth_cognito 0.4.0 [flutter amplify_auth_plugin_interface amplify_core collection plugin_platform_interface]
- amplify_flutter 0.4.0 [amplify_analytics_plugin_interface amplify_api_plugin_interface amplify_auth_plugin_interface amplify_core amplify_datastore_plugin_interface amplify_storage_plugin_interface collection flutter json_annotation meta plugin_platform_interface]
- archive 3.2.1 [crypto path]
- connectivity_plus 2.2.0 [flutter connectivity_plus_platform_interface connectivity_plus_linux connectivity_plus_macos connectivity_plus_web connectivity_plus_windows]
- country_codes 2.1.1 [flutter]
- crypto 3.0.1 [collection typed_data]
- dart_jsonwebtoken 2.4.1 [crypto pointycastle convert collection]
- device_info_plus 3.2.2 [flutter device_info_plus_platform_interface device_info_plus_macos device_info_plus_linux device_info_plus_web device_info_plus_windows]
- dio 4.0.4 [http_parser path]
- drift 1.4.0 [async convert collection meta stream_channel sqlite3]
- drift_inspector 1.0.0 [dart_service_announcement drift synchronized uuid]
- firebase_analytics 9.1.0 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_core 1.12.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_crashlytics 2.5.2 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_dynamic_links 4.0.7 [firebase_core firebase_core_platform_interface firebase_dynamic_links_platform_interface flutter meta plugin_platform_interface]
- firebase_messaging 11.2.6 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- flutter 0.0.0 [characters collection material_color_utilities meta typed_data vector_math sky_engine]
- flutter_hooks 0.18.2+1 [flutter]
- flutter_local_notifications 9.3.2 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path typed_data vector_math]
- flutter_screenutil 5.3.1 [flutter]
- flutter_svg 1.0.3 [flutter meta path_drawing vector_math xml]
- hive 2.0.5 [meta crypto]
- hive_flutter 1.1.0 [flutter hive path_provider path]
- hooks_riverpod 1.0.3 [collection flutter flutter_hooks flutter_riverpod riverpod state_notifier]
- http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
- image_picker 0.8.4+9 [flutter flutter_plugin_android_lifecycle image_picker_for_web image_picker_platform_interface]
- indent 2.0.0
- intl 0.17.0 [clock path]
- json_annotation 4.4.0 [meta]
- logger 1.1.0
- package_info_plus 1.3.1 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web]
- path_provider 2.0.9 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- path_provider_android 2.0.12 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.8 [flutter path_provider_platform_interface]
- permission_handler 9.2.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface]
- phone_number 0.12.0+1 [flutter meta]
- qr_code_scanner 0.7.0 [js flutter flutter_web_plugins]
- shared_preferences 2.0.13 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- shared_preferences_android 2.0.11 [flutter shared_preferences_platform_interface]
- shared_preferences_ios 2.1.0 [flutter shared_preferences_platform_interface]
- shimmer 2.0.0 [flutter]
- sms_autofill 2.2.0 [pin_input_text_field flutter]
- sqlite3_flutter_libs 0.5.4 [flutter]
- sticky_headers 0.2.0 [flutter]
- tuple 2.0.0 [quiver]
- url_launcher 6.0.20 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- webview_flutter 2.0.12 [flutter]
- xml 5.3.1 [collection meta petitparser]

dependency overrides:
- webview_flutter 2.0.12 [flutter]

transitive dependencies:
- amplify_analytics_plugin_interface 0.4.0 [amplify_core flutter meta]
- amplify_api_plugin_interface 0.4.0 [amplify_core collection flutter json_annotation meta]
- amplify_auth_plugin_interface 0.4.0 [flutter meta amplify_core]
- amplify_core 0.4.0 [flutter plugin_platform_interface collection date_time_format meta uuid]
- amplify_datastore_plugin_interface 0.4.0 [flutter meta collection amplify_core]
- amplify_storage_plugin_interface 0.4.0 [flutter meta amplify_core]
- args 2.3.0
- async 2.8.2 [collection meta]
- characters 1.2.0
- charcode 1.3.1
- clock 1.1.0
- collection 1.15.0
- connectivity_plus_linux 1.2.0 [flutter connectivity_plus_platform_interface meta nm]
- connectivity_plus_macos 1.2.1 [connectivity_plus_platform_interface flutter]
- connectivity_plus_platform_interface 1.2.0 [flutter meta plugin_platform_interface]
- connectivity_plus_web 1.2.0 [connectivity_plus_platform_interface flutter_web_plugins flutter]
- connectivity_plus_windows 1.2.0 [connectivity_plus_platform_interface flutter]
- convert 3.0.1 [typed_data]
- cross_file 0.3.2 [flutter js meta]
- dart_service_announcement 1.0.3 [logging synchronized]
- date_time_format 2.0.1
- dbus 0.6.8 [args ffi meta xml]
- device_info_plus_linux 2.1.1 [device_info_plus_platform_interface file flutter meta]
- device_info_plus_macos 2.2.2 [device_info_plus_platform_interface flutter]
- device_info_plus_platform_interface 2.3.0+1 [flutter meta plugin_platform_interface]
- device_info_plus_web 2.1.0 [device_info_plus_platform_interface flutter_web_plugins flutter]
- device_info_plus_windows 2.1.1 [device_info_plus_platform_interface ffi flutter win32]
- ffi 1.1.2
- file 6.1.2 [meta path]
- firebase_analytics_platform_interface 3.1.1 [firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.4.0+6 [firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_core_platform_interface 4.2.4 [collection flutter meta plugin_platform_interface]
- firebase_core_web 1.5.4 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_crashlytics_platform_interface 3.2.1 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_dynamic_links_platform_interface 0.2.1+1 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_platform_interface 3.1.6 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 2.2.7 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- flutter_local_notifications_linux 0.4.1+1 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories]
- flutter_local_notifications_platform_interface 5.0.0 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 2.0.5 [flutter]
- flutter_riverpod 1.0.3 [collection flutter meta riverpod state_notifier]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta typed_data vector_math]
- http 0.13.4 [async http_parser meta path]
- image_picker_for_web 2.1.6 [flutter flutter_web_plugins image_picker_platform_interface]
- image_picker_platform_interface 2.4.4 [cross_file flutter http plugin_platform_interface]
- js 0.6.3
- logging 1.0.2
- matcher 0.12.11 [stack_trace]
- material_color_utilities 0.1.3
- meta 1.7.0
- nm 0.4.4 [dbus]
- package_info_plus_linux 1.0.3 [package_info_plus_platform_interface flutter path]
- package_info_plus_macos 1.3.0 [flutter]
- package_info_plus_platform_interface 1.0.2 [flutter meta plugin_platform_interface]
- package_info_plus_web 1.0.4 [flutter flutter_web_plugins http meta package_info_plus_platform_interface]
- package_info_plus_windows 1.0.4 [package_info_plus_platform_interface ffi flutter win32]
- path 1.8.0
- path_drawing 1.0.0 [vector_math meta path_parsing flutter]
- path_parsing 1.0.0 [vector_math meta]
- path_provider_linux 2.1.5 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.5 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.3 [flutter platform plugin_platform_interface]
- path_provider_windows 2.0.5 [ffi flutter path path_provider_platform_interface win32]
- permission_handler_android 9.0.2 [flutter permission_handler_platform_interface]
- permission_handler_apple 9.0.2 [flutter permission_handler_platform_interface]
- permission_handler_platform_interface 3.7.0 [flutter meta plugin_platform_interface]
- permission_handler_windows 0.1.0 [flutter permission_handler_platform_interface]
- petitparser 4.4.0 [meta]
- pin_input_text_field 4.1.1 [flutter]
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- pointycastle 3.5.1 [collection convert js]
- process 4.2.4 [file path platform]
- quiver 3.0.1+1 [matcher]
- riverpod 1.0.3 [collection meta state_notifier]
- shared_preferences_linux 2.1.0 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_macos 2.0.3 [flutter shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.0.0 [flutter]
- shared_preferences_web 2.0.3 [flutter flutter_web_plugins shared_preferences_platform_interface]
- shared_preferences_windows 2.1.0 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- sky_engine 0.0.99
- source_span 1.8.1 [collection path term_glyph]
- sqlite3 1.5.1 [collection ffi meta]
- stack_trace 1.10.0 [path]
- state_notifier 0.7.2+1 [meta]
- stream_channel 2.1.0 [async]
- string_scanner 1.1.0 [charcode source_span]
- synchronized 3.0.0
- term_glyph 1.2.0
- timezone 0.8.0 [path]
- typed_data 1.3.0 [collection]
- url_launcher_android 6.0.15 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.0.15 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.0.0 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.0.0 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.0.5 [flutter plugin_platform_interface]
- url_launcher_web 2.0.8 [flutter flutter_web_plugins url_launcher_platform_interface]
- url_launcher_windows 3.0.0 [flutter url_launcher_platform_interface]
- uuid 3.0.5 [crypto]
- vector_math 2.1.1
- win32 2.4.1 [ffi]
- xdg_directories 0.2.0+1 [meta path process]

Device

(Maybe more)

  • iPhone XR
  • iPhone X
  • iPhone 13

OS

(Maybe more)

  • 15.1.1
  • 14.7.1
  • 14.6

CLI Version

N/A

Additional Context

When idToken is expired, I called fetchAuthSession to refresh token, but sometimes had a exception, like Your session has expired. or Session expired could not fetch user sub.

When I got the exception on first time, I called sing out and signin then fetchAuthSession again, sometimes it return a exception, like There is no user signed in to retreive user sub.

How do I resolve this issue?
Thank you.

Code

    CognitoAuthSession session;
    try {
      refreshTokenLog += 'Fetch Auth Session.\n';
      session = await Amplify.Auth.fetchAuthSession(options: CognitoSessionOptions(getAWSCredentials: true))
          as CognitoAuthSession;
    } on AmplifyException catch (error) {
      refreshTokenLog += 'Fetch auth session fail: ${error.message}\n';
      try {
        refreshTokenLog += 'Try to sign out\n';
        await signOut();
      } on AmplifyException catch (error) {
        refreshTokenLog += 'Sign out fail: ${error.message}\n';
      }
      refreshTokenLog += 'Try to sign in';
      final bool isSignIn = await signIn();
      if (isSignIn == false) {
        refreshTokenLog += 'Sign in fail\n';
        apiLogger.i(refreshTokenLog);
        debugLogger.i(refreshTokenLog);
        return;
      }
      try {
        refreshTokenLog += 'Try to fetch auth session\n';
        session = await Amplify.Auth.fetchAuthSession(options: CognitoSessionOptions(getAWSCredentials: true))
            as CognitoAuthSession;
      } on AmplifyException catch (error) {
        refreshTokenLog += 'fetch auth session fail again: ${error.message}\n';
        apiLogger.i(refreshTokenLog);
        debugLogger.i(refreshTokenLog);
        return;
      }
    }
@Jordan-Nelson
Copy link
Member

Hi @jack24254029 - Can you confirm you have seen this on both iOS and Android?

@Jordan-Nelson Jordan-Nelson added pending-triage This issue is in the backlog of issues to triage auth Issues related to the Auth Category labels Mar 7, 2022
@jack24254029
Copy link
Author

jack24254029 commented Mar 7, 2022

Hi @Jordan-Nelson
According to my log, I search these user's device platform is iOS and device follow below list:

  • iPhone XR / 14.7.1
  • iPhone X / 14.6
  • iPhone 13 / 15.1.1

@jack24254029
Copy link
Author

I don't see this on Android, but I will keep observe it.

@Jordan-Nelson
Copy link
Member

@jack24254029 Okay, thanks for that info.

Are you able to reproduce this behavior, or have you only been able to observe it via the logs?

@jack24254029
Copy link
Author

jack24254029 commented Mar 7, 2022

I am not sure how to reproduce this behavior.
My colleague has installed release app, he told me one thing that app couldn't refresh data with API when open it after a week (because app can't fetchAtuhSession), so I think that user NO refresh token after a week or more maybe can reproduce this behavior.

Yes, I only able to observe it with logs on production environment.

@Jordan-Nelson
Copy link
Member

Okay. What is the implementation of signIn(), which is referenced in the line final bool isSignIn = await signIn();? Is the prompting the user to sign back in with username / password?

@jack24254029
Copy link
Author

No, we use a rule to generate password.

  Future<bool> signIn() async {
    final ProfileData? profile = await ProviderContainer().read(profileRepositoryProvider).getProfile();
    if (profile == null) {
      return false;
    }
    final SignInResult signInResult = await Amplify.Auth.signIn(
      username: profile.account,
      password: 'pwd_${appId}_${profile.account}',
    );
    return signInResult.isSignedIn;
  }

@Jordan-Nelson Jordan-Nelson added the to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided label Mar 10, 2022
@Jordan-Nelson
Copy link
Member

@jack24254029 Is it possible that this is also happening after an initial log in as well (do you have logs in that scenario), or does it only occur in the scenario you have above? It could help to know if this is only happening after the initial session expires, or it it can be observed in other scenarios.

@Jordan-Nelson Jordan-Nelson added the pending-community-response Pending response from the issue opener or other community members label Mar 10, 2022
@Jordan-Nelson
Copy link
Member

There is a similar issue (#1271) reported for Android, but it is being observed after the initial sign in.

@jack24254029
Copy link
Author

I don't have log after the initial session, but I can add it.
I think relogin is same with initial sign in.

@Jordan-Nelson Jordan-Nelson removed the pending-community-response Pending response from the issue opener or other community members label Mar 11, 2022
@Jordan-Nelson
Copy link
Member

@jack24254029 do you have an idea of how frequently you see this happen? Roughly what percentage of the Try to fetch auth session logs are followed by fetch auth session fail again?

@Jordan-Nelson Jordan-Nelson added the pending-community-response Pending response from the issue opener or other community members label Mar 11, 2022
@jack24254029
Copy link
Author

Fetch auth session fail first time about two or three users pre day.
In these users have zero or one user fetch auth session fail second times.

@jack24254029
Copy link
Author

Active users of day in my app about thirty (Android and iOS)

@Jordan-Nelson
Copy link
Member

@jack24254029 is error.message always the same in the code snippet below? The issue description says, "but sometimes had a exception, like Your session has expired. or Session expired could not fetch user sub".

Are those two separate errors you have seen, and are those the exact messages? Have you seen any others?

refreshTokenLog += 'fetch auth session fail again: ${error.message}\n';

@Jordan-Nelson Jordan-Nelson added pending-community-response Pending response from the issue opener or other community members and removed pending-community-response Pending response from the issue opener or other community members labels Mar 11, 2022
@jack24254029
Copy link
Author

I only saw two errors on fetch fail first time and one error on fetch fail second times

FetchAuthSession Fail (First time)
Uid: 203068
Error Message:
Your session has expired.
FetchAuthSession Fail (First time)
Uid: 192598
Error Message:
Session expired could not fetch user sub

**After relogin**

FetchAuthSession (Second times)
Uid: 192598
Error Message:
There is no user signed in to retreive user sub

@Jordan-Nelson Jordan-Nelson removed the pending-community-response Pending response from the issue opener or other community members label Mar 14, 2022
@Jordan-Nelson Jordan-Nelson self-assigned this Mar 14, 2022
@Jordan-Nelson
Copy link
Member

@jack24254029 I am unable to reproduce this. I have run an automated test that attempts to call fetchAuthSession every 5 minutes. If fetchAuthSession fails, sign out / sign in is called, and then fetchAuthSession is called again. All failures of fetchAuthSession are logged. The app I am testing with has session token expiration set to 5 minutes and refresh token expiration set to 60 minutes. I consistently see fetchAuthSession succeed for 60 minutes until the refresh token expires. At that point the tests calls sign out / sign in, and then consistently is able to call fetchAuthSession. I do not see a second failure after sign out / sign in. This is the behavior that I would expect.

Can you log the full AmplifyException? Right now your logs contain the message. It would be helpful to see the recoverySuggestion and underlyingException if those exist.

Can you also tell me what settings you have for token expiration (session token and refresh token)? You can find this in Cognito under "General Settings" -> "App Clients".

For reference, here is the integration test code I am running. signIn() is similar to your signIn() method. It uses username/password stored in memory to sign the user back in.

testWidgets(
  'should sign a user back in after session expiration',
  (WidgetTester tester) async {
    await signIn();
    for (int i in List.generate(1000, (index) => index)) {
      print('starting test $i');
      AuthSession? session;
      int count = 0;
      while (session == null) {
        count++;
        try {
          session = await Amplify.Auth.fetchAuthSession(
            options: CognitoSessionOptions(getAWSCredentials: true),
          );
          print('Fetch auth session succeeded.');
        } on AmplifyException catch (error) {
          print(
            'Fetch auth session failed - count: $count, error: ${error.message}',
          );
          await Amplify.Auth.signOut();
          await signIn();
        }
      }
      await Future.delayed(Duration(minutes: 5));
    }
  },
  timeout: Timeout(Duration(days: 1)),
);

@Jordan-Nelson Jordan-Nelson added the pending-community-response Pending response from the issue opener or other community members label Mar 15, 2022
@jack24254029
Copy link
Author

Our case is that when a user had login the app, and did not open the app more than seven days.

@Jordan-Nelson
Copy link
Member

Our case is that when a user had login the app, and did not open the app more than seven days.

What is the refresh token expiration set to?

@brunovsiqueira
Copy link

@brunovsiqueira You mention reducing the refresh token duration as well - how low have you set it? If the refresh token expires, then the expected behavior is to expire the session completely, which I've been able to reproduce. In the case where just the access token has expired, I haven't yet been able to reproduce it.

I have set to the minimum possible: access 10 min, refresh 1 hours. When these were my app client configurations, this error was happening a lot.

Then I reverted it app client tokens configurations to access 1 hour and refresh 24 hours and it seems to be gone or happening a lot less.

When I was investigating it I found out a big delay (more than 10 minutes, my access token expiration) between the signIn event in cognito console and the SessionExpired exception being thrown when fetching credential. I couldn't find a reason why this delay happened since the fetchAuthSession call was right after the signIn call. Additionaly, I don't understand why session wasn't refreshed when getting credentials, even when it is 10+ minutes after signIn.

@dnys1
Copy link
Contributor

dnys1 commented Mar 25, 2022

I believe it's because using the refresh token to get new tokens only returns a new access and ID token, meaning the refresh token has a fixed life. And once it's expired, you can no longer get new access/ID tokens so your session must expire. If your access token life is set to 10 minutes, that means you'll be using the refresh token every 10 minutes.

@brunovsiqueira
Copy link

Yeah, that's totally true. What I think is strange is the fact that user just signed in and in his first try to refresh its access token (I deduced it is first try because it happens right -sequentially- after signIn) gets SessionExpired.

@Jordan-Nelson
Copy link
Member

New log on Android

FetchAuthSession Fail (First time)
Date time: Date Time: 2022-03-17 15:59:03.159 (GMT+08:00)
App version: 1.0.0.5 (339)
Platform: Android
Device: ASUS_I002D
OS Version: 11
Uid: 123917
Error Message:
Your session has expired.
Recovery Suggestion:
Please sign in and reattempt the operation.

@jack24254029 - Are you able to tell if the user attempted to sign in after this? Since the refresh token is set to 30 days, the user will have to re-authenticate with a username and password after 30 days. So in this case, this may be expected behavior.

@jack24254029
Copy link
Author

@jack24254029 - Are you able to tell if the user attempted to sign in after this? ....

Yes, the user can sign in after this.

@Jordan-Nelson Jordan-Nelson removed the pending-community-response Pending response from the issue opener or other community members label Apr 25, 2022
@Jordan-Nelson Jordan-Nelson removed their assignment Apr 28, 2022
@Jordan-Nelson Jordan-Nelson removed the to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided label Apr 28, 2022
@brunovsiqueira
Copy link

brunovsiqueira commented Apr 28, 2022

Any updates on this? We have another user (Galaxy S8) which is unable to signIn because SessionExpiredException is thrown right after sign in. He tried dozens of times but same behavior keeps happening.

Logs:
10:37:44.731 Login: isSignedIn - true | SignInStep - DONE | AdditionalInfo - null !
10:37:44.758 SessionExpiredException(message: Your session has expired., recoverySuggestion: Please sign in and reattempt the operation., underlyingException: null)

Same behavior I explained earlier: I can see the "Password:Success" on all of his attempts at "User event history" but his Android device is not showing up in the "Device tracking log" cognito session. Actually he tried with an iPhone 11 with same user credentials and he could login normally.

@MarlonJD
Copy link
Contributor

Same issue user's cannot sign-in after 1 hour. User pool settings like: 30 days, 1 hour, 1 hour. It cannot be refreshed after 1 hour. I tried 30 Days, 5min, 5min. I cannot sign-in or system cannot be refreshed after 5 minutes.
It's gives:

[Amplify] AWSMobileClient Event listener - signedOutUserPoolsTokenInvalid
[AuthErrorHandler] The operation couldn’t be completed. (Amplify.AuthError error 7.)
flutter: SessionExpiredException(message: Session expired could not fetch user sub, recoverySuggestion: Invoke Auth.signIn to re-authenticate the user, underlyingException: null)

I added on SessionExpiredException catch (e) { to fetchAuthSession and tried again and no luck. It's the so critical error. How can we refresh token?

Here's my function

    try {
      debugPrint("Tring to fetch auth");

      CognitoAuthSession res = await Amplify.Auth.fetchAuthSession(
              options: CognitoSessionOptions(getAWSCredentials: true))
          .timeout(
        const Duration(seconds: 5),
      ) as CognitoAuthSession;
      debugPrint('Session Sign In Status = ${res.isSignedIn}');
      res.isSignedIn ? isSigned(true) : isSigned(false);
    } on SessionExpiredException catch (e) {
      debugPrint('Session Expired: $e');
      debugPrint("Tring to fetch auth agin");
      try {
        CognitoAuthSession res = await Amplify.Auth.fetchAuthSession(
                options: CognitoSessionOptions(getAWSCredentials: true))
            .timeout(
          const Duration(seconds: 5),
        ) as CognitoAuthSession;
        debugPrint('Session Sign In Status = ${res.isSignedIn}');
        res.isSignedIn ? isSigned(true) : isSigned(false);
      } on AmplifyException catch (e) {
        debugPrint("Error when tring to refresh: ${e.toString()}");
      }
    } on AmplifyException catch (e) {
      debugPrint(e.toString());
    }

@MarlonJD
Copy link
Contributor

@Jordan-Nelson
Copy link
Member

Jordan-Nelson commented Aug 2, 2022

Hello everyone - We have been unable to reproduce this issue. However, I am going to label this as a bug since the info provided indicates there may be a race condition present.

We have recently released a new developer preview version of the Auth category (amplify_flutter v1.0.0-next.0). This new version is a full re-write of the auth category in dart. While the primary purpose of this re-write was to add support for Web and Desktop, we also implemented a new design using state machines that is intended to solve issues such as race conditions. You can read more about the developer preview release in the blog post and docs.

I believe this will address the issue described above. If you are willing to experiment with this new version while it is in dev-preview we would appreciate any feedback you have.

I will provide an update on this ticket once this version is out of dev-preview and is ready for production use.

Let me know if you have any questions.

@Jordan-Nelson Jordan-Nelson added bug Something is not working; the issue has reproducible steps and has been reproduced pending-release Issues that have been addressed in main but have not been released and removed pending-triage This issue is in the backlog of issues to triage labels Aug 2, 2022
@Jordan-Nelson
Copy link
Member

@MarlonJD - Were you able to reproduce this issue consistently? If so, could you share the steps you took to reproduce it?

@MarlonJD
Copy link
Contributor

@MarlonJD - Were you able to reproduce this issue consistently? If so, could you share the steps you took to reproduce it?

Hey, i couldn't remember so much, it was so long ago, but i remember that it was solved when i closed remember me option on cognito console on AWS. Maybe you can reproduce same error with remember me option true.

@Jordan-Nelson Jordan-Nelson added fixed-in-release-candidate Issues that have been addressed in the current release-candidate branch and removed pending-release Issues that have been addressed in main but have not been released labels Mar 2, 2023
@Jordan-Nelson
Copy link
Member

@jack24254029 - We believe that this issue has been addressed in v1.0.0 of Amplify Flutter, which is now stable. Would you please upgrade to the latest version and let us know if you still observe this issue?

This release also includes web and desktop support for Auth, API, Analytics, and Storage. You can see the list of new features and bug fixes in the release notes, and see more details on how to migrate in the upgrade guide.

@Jordan-Nelson Jordan-Nelson added the pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days. label Apr 17, 2023
@jack24254029
Copy link
Author

OK. I will try it. Thank you very much.

@Jordan-Nelson
Copy link
Member

Hello @jack24254029 - I wanted to check in to see if you have had a chance to migrate to the latest version of amplify flutter. Let me know if you are facing any issues.

@Jordan-Nelson Jordan-Nelson self-assigned this May 1, 2023
@jack24254029
Copy link
Author

I had migrated it in Dev enviroment. It looks like well.

@Jordan-Nelson
Copy link
Member

Great to hear. I am going to close this out. If you face any issue when moving to production, please let me know and I can re-open this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Issues related to the Auth Category bug Something is not working; the issue has reproducible steps and has been reproduced fixed-in-release-candidate Issues that have been addressed in the current release-candidate branch pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days.
Projects
None yet
Development

No branches or pull requests

5 participants