I using AWS cognito
to verify the user's phone number. I have a problem:
When the user enter his details, I send it to AWS.
AWS try to send code to the user's phone number, but if the user enter a wrong number AWS return exception "invalid phone number". So I ask the user to update the number, but when I try to update it in AWS, they return exception
"the user is not authenticated". How can I update the number to the right number after the user just signup and still not confirmed?
This is my code:
// Create a CognitoUserAttributes object and add user attributes
CognitoUserAttributes userAttributes = new CognitoUserAttributes();
// Add the user attributes. Attributes are added as key-value pairs
// Adding user's given name.
// Note that the key is "given_name" which is the OIDC claim for given name
userAttributes.addAttribute("name", userName);
userAttributes.addAttribute("family_name", userFamily);
// Adding user's phone number
userAttributes.addAttribute("phone_number", prepareValidPhoneNumberForAWS(userPhone));
SignUpHandler signupCallback = new SignUpHandler()
{
int t=0;
@Override
public void onSuccess(CognitoUser cognitoUserUser, boolean userConfirmed, CognitoUserCodeDeliveryDetails cognitoUserCodeDeliveryDetails)
{
// Sign-up was successful
// Check if this user (cognitoUser) has to be confirmed
if(!userConfirmed)
{
t=0;
// This user has to be confirmed and a confirmation code was sent to the user
// cognitoUserCodeDeliveryDetails will indicate where the confirmation code was sent
// Get the confirmation code from user
}
else
{
// The user has already been confirmed
t=1;
}
}
@Override
public void onFailure(Exception exception)
{
// Sign-up failed, check exception for the cause
exception.printStackTrace();
}
};
userPool.signUpInBackground(currentUser.getUser_id(),currentUser.getUuid(),userAttributes,null,signupCallback);
Amazon Cognito can automatically verify email addresses or phone numbers. To do this verification, Amazon Cognito sends a verification code or a verification link. For email addresses, Amazon Cognito can send a code or a link in an email message. For phone numbers, Amazon Cognito sends a code in an SMS text message.
You can't change standard user pool attributes after a user pool is created. Instead, create a new user pool with the attributes that you want to require for user registration. Then, migrate existing users to the new user pool by using an AWS Lambda function as a user migration trigger.
To update a cognito user's attributes use the admin-update-user-attributes command, specifying the user-pool-id , username and user-attributes parameters. Copied! In the example above, we've set the gender attribute of the user to m and their name attribute to john smith .
AWS Cognito User Pool will send verification code by email or sms and the user enters the code to get verified with the User Pool. User enters username and password and logs in with Cognito User Pool in which case a token will be provided by Cognito upon successful login.
Currently this usecase is not supported by Cognito because customer needs to be signed-in to update the phone number and unconfirmed accounts cannot sign-in. One option is to let user create a new account with the correct email address. Another option is that end user contacts developer, developer can use AdminUpdateUserAttributes to update the user phone number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With