6
votes

Hi I would like to have my app can be signup either using Email Address or Phone Number using AWS Cognito Pool checking on Allow both email addresses and phone numbers (users can choose one).

But I want to ask users for Email address later (If they signed up with Phone number or ask for phone number if they signed up with Email address)

And I found that the options Email address or phone number in Cognito Userpool can not do the alias between Phone number and Email address but uses them as a Username instead.

In the same time, the Username option requires us to have a unique Username to signup but Username is no point in my application and I don't want user to type in many boxes while signing up.

Is there anyway I can achieve what I want using AWS Cognito UserPool ?

1

1 Answers

1
votes

When you set up your Cognito user pool to begin with, if you select the option to "let users use email as username" and also make sure you require phone verification.

https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-email-phone-verification.html

Then when your users sign up, if you handle your front end auth/signup/confim flow yourself as seen here: https://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-user-identity-pools-javascript-examples.html

You can confirm whatever method you want. I highly recommend you read the link above and handle the confirm flow yourself.

Also, when you get your user attributes object on the front end you can see what is verified:

{  
   "details":[  
      {  
         "Name":"sub",
         "Value":"ceba8336-4234-4c3d-8abc-af08c002b4de"
      },
      {  
         "Name":"email_verified",
         "Value":"true"
      },
      {  
         "Name":"phone_number_verified",
         "Value":"false"
      },
      {  
         "Name":"email",
         "Value":"[email protected]"
      }
   ]
}