Add Authentication Service

Create Authentication Components

Next, you will add authentication capabilities for our application using Amazon Cognito. To do this, we simply need to run the following command from our project directory:

amplify add auth

You can only add one Authentication provider to your Amplify project.

Select Default configuration for the first choice. Init Amplify

Select Username for the user to sign in with a username: Init Amplify

Select, Yes I want to make additional changes. We do this because we want to require some additional profile fields: Init Amplify

In the next step, highlight these additional attributes (by using the space bar):

  • Given Name (e.g., First name)
  • Family Name (e.g., Last name)
  • Address Init Amplify Init Amplify

Press Enter to accept the changes. Then press Enter again to bypass any additional capabilities and to complete the authentication setup. Init Amplify

Push the authentication changes to AWS

The amplify add auth command only saved files locally. We need to run the amplify push command to deploy our changes to our AWS account.

To push our changes to AWS, run the following:

amplify push

You will be prompted to complete the changes. Select Y and the deployment will begin. Init Amplify

You can run the amplify status command to get a list of all pending and completed changes for your project.

Once the deployment is completed, you will receive a success message. Init Amplify