Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid phone number format on Cognito signup

Im tryng to create a new user on my cognito user pool via nodeJS but i keep getting wrong phone number error...but i use the same format of number to send SMS via SNS services, i dont understand why this is happening

signup method:

module.exports.post = async (username,password,email,phoneNumber) => {
    const environment = {
        UserPoolId: xxxxxxx,
        ClientId: xxxxxx,
    }
    return new Promise((reject,resolve) => {
        const userPool = new AmazonCognitoIdentity.CognitoUserPool(environment);
        const emailData = {
            Name: 'Email',
            Value: email
        };
        const userData = {
            Name: 'Usuário',
            Value: username
        };
        const phoneData = {
            Name: 'Telefone',
            Value: phoneNumber
        };
        const emailAttribute = new AmazonCognitoIdentity.CognitoUserAttribute(emailData);
        const userAttribute = new AmazonCognitoIdentity.CognitoUserAttribute(userData);
        const phoneAttribute = new AmazonCognitoIdentity.CognitoUserAttribute(phoneData);

        userPool.signUp(username,password,[emailAttribute,userAttribute, phoneAttribute], null, (err,data) => {
        if(err) console.log(err);
        resolve(data);
        });
    });
}

the number format im passing:

+5521979724910

the error :

{ code: 'InvalidParameterException',
  name: 'InvalidParameterException',
  message: '1 validation error detected: Value \'phone number\' at \'userAttributes.2.member.name\' failed to satisfy constraint: Member must satisfy regular expression pattern: [\\p{L}\\p{M}\\p{S}\\p{N}\\p{P}]+' }

Any ideas?

like image 657
Daniel Bezerra De Menezes Avatar asked Nov 29 '18 15:11

Daniel Bezerra De Menezes


People also ask

What does phone number format invalid mean?

The recipient's number is invalid and cannot be recognised by our system for delivery. This may be caused if: The mobile number is not in the correct international format, it was too long/short, or it was entered incorrectly. The customer may have also opted out from receiving text messages.

How do I verify a phone number with Cognito?

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.

How do I set up authentication in Cognito?

Go to AWS Cognito service and click “Manage Identity Pools”. 2. Enter “Identity pool name”, expand the “Authentication providers” section and select “Cognito” tab. This is where the Cognito authentication provider will be registered with the Identity pool.

How do you authenticate on Amazon Cognito?

Configure the external provider in the Amazon Cognito console. Choose Manage Identity Pools from the Amazon Cognito console home page : Choose the name of the identity pool where you want to enable Login with Amazon as an external provider. The Dashboard page for your identity pool appears.


2 Answers

The Name attribute value should be phone_number instead of Telefone

const phoneData = {
        Name : 'phone_number',
        Value : '+15555555555'
    };
like image 175
AlexK Avatar answered Sep 20 '22 15:09

AlexK


use attribute name as 'phone_number'

Note: add the country code along with the phone number value. Otherwise it will throw another error

like image 44
Akhila KSaju Avatar answered Sep 20 '22 15:09

Akhila KSaju