amazon-cognito-identity-dart-2
amazon-cognito-identity-dart-2 copied to clipboard
How can i save usersession locally?
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.
There is an example for this in the README and you can review this issue on how to refresh token to keep session valid.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.