Question:
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
// 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); |
Answer:
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.