Flutter sign up confirm via phone otp in aws amplify

Viewed 673

How to add phone and confirm sign up via phone otp and not with email otp

2 Answers

try amazon_cognito_identity_dart package.

//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);

If I understand correctly, you're having some configuration issues with Cognito.
In order to enable the Phone OTP, you should connect to AWS, pick your project and go to

User Pools > Attributes

and setup your configuration to use the Phone and/or email.
Then you have to go to

User Pools > MFA and verifications

and pick the phone number as the Attribute to verify.

Related