furaiev / amazon-cognito-identity-dart-2

Unofficial Amazon Cognito Identity Provider Dart SDK, to easily add user sign-up and sign-in to your mobile and web apps with AWS.
MIT License
187 stars 114 forks source link

How can i save usersession locally? #177

Closed udaysagartammina closed 1 year ago

udaysagartammina commented 2 years ago

I am working with a phone number and opt login. I entered the phone number pass the phone number value in step1 and I received opt entered the value in step2. The enter flow is working fine, my concession is once I removed the app instance I got this error Unhandled Exception: LateInitializationError: Field 'userSession' has not been initialized.

final userPool = CognitoUserPool( 'us-east-1_123asd4', 'zxcsdcew433432dd', );

Step1: cognitoUser = CognitoUser(phonenumber, userPool); try { CognitoUserSession? cognitoUserSession = await cognitoUser.initiateAuth( AuthenticationDetails( authParameters: [ AttributeArg( name: 'phone_number', value: "+911234567890", ), ], ), ); print("login success>>>>>$cognitoUserSession"); } on CognitoClientException catch (e) { print("login failed>>>>>$e"); } catch (e){ print("login >>>>>$e"); }

Step2: CognitoUserSession? cognitoUserSession = await cognitoUser.sendCustomChallengeAnswer(otp); print("jwtToken >>>>>$cognitoUserSession!.idToken.jwtToken.toString()"); print("refreshToken >>>>>$cognitoUserSession.refreshToken!.token.toString()");

Thanks in advance.

Lorenzohidalgo commented 2 years ago

There is an example for this in the README and you can review this issue on how to refresh token to keep session valid.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 year ago

This issue was closed because it has been inactive for 14 days since being marked as stale.