How to maintain usersession?

Viewed 34

I am using this flutter package - https://pub.dev/packages/amazon_cognito_identity_dart_2

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.

0 Answers
Related