4

I am unable to know how to do passwordless signin with OTP using cognito in flutter. I just need assistance with the flutter code for sending the OTP and answering the auth challenger with any working cognito/amplify package.

1 Answer 1

5

I was able to do with this package: amazon_cognito_identity_dart_2

//Create a cognito user
CognitoUser cognitoUser1;

//Send OTP
 cognitoUser1 = CognitoUser(phoneNumber.text, widget.userPool);
  try {
    CognitoUserSession cognitoUserSession =
        await cognitoUser1.initiateAuth(
      AuthenticationDetails(
        authParameters: [
          AttributeArg(
            name: 'phone_number',
            value: phoneNumber.text,
          ),
        ],
      ),
    );
  } catch (cognitoUserCustomChallengeException) {}
  

//Authenticate the user
CognitoUserSession cognitoUserSession = await cognitoUser1.sendCustomChallengeAnswer(otp.text);

print("jwtToken " + cognitoUserSession.accessToken.jwtToken);
print("refreshToken " + cognitoUserSession.refreshToken.token);
1
  • Can you show more of the code pls or a bit more explanation because I'm stuck on the same issue and don't know how to approach it Mar 31, 2022 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.