amazon-cognito-identity-dart-2 icon indicating copy to clipboard operation
amazon-cognito-identity-dart-2 copied to clipboard

How can i save usersession locally?

Open udaysagartammina opened this issue 3 years ago • 1 comments

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.

udaysagartammina avatar Dec 13 '21 10:12 udaysagartammina

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

Lorenzohidalgo avatar Feb 11 '22 09:02 Lorenzohidalgo

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

github-actions[bot] avatar Jul 27 '23 02:07 github-actions[bot]

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

github-actions[bot] avatar Aug 10 '23 02:08 github-actions[bot]