Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I signup with email or phone number with a password without Username and alias them later

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 ?

like image 781
Tanapat Sainak Avatar asked Sep 14 '17 08:09

Tanapat Sainak


People also ask

What is Cognito sub?

Cognito sub attribute: When importing the users to a new pool, users will be assigned new Cognito-generated unique IDs (the sub attribute). Federated users: custom attributes for federated users will not be exported and the federated user will get a new value for the sub attribute when they log in to the new user pool.

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.

Can we change username in Cognito?

The user name is a fixed value that users can't change. If you mark an attribute as an alias, users can sign in with that attribute in place of the user name. You can mark the email address, phone number, and preferred username attributes as aliases.

How can I verify my Cognito account?

When a user updates their email address or phone number in your app, Amazon Cognito immediately sends a message with a verification code to a user if you configured your user pool to automatically verify that attribute. The user must then provide the code from the verification message to your app.


1 Answers

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]"
      }
   ]
}
like image 193
Ryan Breece Avatar answered Oct 11 '22 03:10

Ryan Breece