5

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

Midhilaj
  • 4,905
  • 9
  • 45
  • 88

2 Answers2

3

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

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
FDuhen
  • 4,097
  • 1
  • 15
  • 26