aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.32k stars 247 forks source link

Getting an Error on iPhone 12 & 12 pro #747

Closed androidshivam closed 2 years ago

androidshivam commented 3 years ago

Description of bugs: Unhandled Exception: SessionExpiredException(message: Session expired could not fetch user sub, recoverySuggestion: Invoke Auth.signIn to re-authenticate the user, underlyingException: null)

To Reproduce: While installing the app in iOS 12 & 12Pro

Expected Behavior: Initialise the AWS plugins and fetch the current session of user null if User is not signin else gives null

Stack Trace:

[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: SessionExpiredException(message: Session expired could not fetch user sub, recoverySuggestion: Invoke Auth.signIn to re-authenticate the user, underlyingException: null)

0 AmplifyAuthCognitoMethodChannel.fetchAuthSession (package:amplify_auth_cognito/method_channel_auth_cognito.dart:239:7)

#1 AmplifyAuthCognito.fetchAuthSession (package:amplify_auth_cognito/amplify_auth_cognito.dart:113:17) #2 CognitoService.isSignedIn (package:total_vision/services/cognito_service.dart:470:21) #3 CognitoService.configureAmplify (package:total_vision/services/cognito_service.dart:151:20) **Code Snippet:** Future isSignedIn() async { final session = await Amplify.Auth.fetchAuthSession( options: CognitoSessionOptions(getAWSCredentials: true)); if(session.isSignedIn){ await getUserData(); await fetchSession(); unawaited(Future.delayed(Duration.zero, locator().queryAll)); } return session.isSignedIn; } **Environment(please complete the following information):** SDK Version: 2.2.3 Dependency Manager: CocoaPods version 1.10.1 Xcode Version: Xcode 12.5.1, Build version 12E507 **Device: iPhone 12 & iPhone 12 Pro** iOS Version: 14.6 ![Simulator Screen Shot - iPhone 12 Pro Max - 2021-07-26 at 11 31 25](https://user-images.githubusercontent.com/45711013/126941003-8301cbe3-8eb6-4fab-92c1-0ef183ccbbf5.png)
yashaeologic commented 3 years ago

Hey Shivam,

Are you using dependency in pub spec or using the whole package as custom dependancy.

androidshivam commented 3 years ago

Hey Shivam,

Are you using dependency in pub spec or using the whole package as custom dependancy.

name: total_vision description: A new Flutter application. publish_to: 'none' version: 1.0.1+1

environment: sdk: ">=2.7.0 <3.0.0"

dependencies: flutter: sdk: flutter provider: ^5.0.0 rx_ble: git: url: git://github.com/IoTReady/plugin-flutter-rx-ble.git ref: master get_it: ^6.0.0 pin_input_text_field: path: ./local_plugins/flutter_pin_text_field shared_preferences: ^2.0.6 package_info: ">=0.4.0+17 <2.0.0" lottie: ^1.0.1 font_awesome_flutter: ^9.0.0 flutter_svg: ^0.21.0+1 country_pickers: ^2.0.0 flutter_datetime_picker: ^1.3.8 date_format: ^2.0.2 progressive_image: ^1.0.1 equatable: ^2.0.0 bloc: ^7.0.0 flutter_bloc: ^7.0.0 http: ^0.13.1 image_picker: ^0.7.4 image_cropper: ^1.2.3 flutter_image_compress: ^0.7.0 path_provider: ^2.0.1 amplify_flutter: ^0.2.0 amplify_auth_cognito: ^0.2.0 amplify_api: ^0.2.0 url_launcher: ^6.0.3 permission_handler: ^7.1.0 app_settings: ^4.1.0 share: ^2.0.1 calendarro: path: ./local_plugins/flutter_calendarro

dev_dependencies: flutter_test: sdk: flutter pedantic: ^1.8.0 flutter_launcher_icons: ^0.9.0

flutter_icons: android: false ios: true image_path: "assets/ios_icon.jpg"

flutter: uses-material-design: true assets:

haverchuck commented 3 years ago

@androidshivam Was there a previously authenticated user on this device, and the refresh token expired?

androidshivam commented 3 years ago

@androidshivam Was there a previously authenticated user on this device, and the refresh token expired?

I've tested on multiple devices.I'm facing this issue on first install as well

abdallahshaban557 commented 2 years ago

@androidshivam are you still facing this issue?

dnys1 commented 2 years ago

@androidshivam - is the confusion that fetchAuthSession is throwing an exception instead of returning a value of isSignedIn = false? Can you add a try/catch block and handle a SessionExpiredException the same way you'd handle a value of false for isSignedIn?

abdallahshaban557 commented 2 years ago

@androidshivam - did you try the workaround provided by @dnys1 ?

Jordan-Nelson commented 2 years ago

@androidshivam - If you are still facing this issue after trying the solution above, please let us know. Otherwise we will close it out. Thanks.