Amplify UI Components is an open-source toolkit that makes it easier for developers to add common use cases to their applications. The toolkit comes out of the box with a UI interface that is connected to Amplify’s backend services.
In this example, we will use the Authenticator UI Component to allow users to signup and signin.
We have bootstrapped this application using the Angular CLI.
- Login or Create an AWS Account.
- In a terminal, clone this repo.
- Install the Amplify CLI
npm install -g @aws-amplify/cli
. Ensure you are in the directory you just cloned. - If it’s your first time using the CLI, you will need to configure it by running
amplify configure
. Follow the instructions to create an IAM profile locally. - Now let’s initialize an Amplify project in this directory.
amplify init
$ amplify init
? Enter a name for the environment dev
? Choose your default editor: (pick an editor)
? Do you want to use an AWS profile? Y (this should be the profile you created in step #4)
- Lastly, the CLI will provision our backend resources using the config files in the
amplify
directory. To provision these resources in the cloud, runamplify push
. Confirm you want to use the Auth category.
npm install
npm run start
- The app should run on http://localhost:4200/. Try creating an account and signing in.
Now that you've built the app, let's take a look under the hood and explore how it works.
Let's dive into the frontend components. In this app, the important logic is in app.component.ts
.
Using the *ngIf directive we can conditionally render the application based on whether a user is authenticated and signed in. If a user isn’t signed in, let’s display the AmplifyAuthenticator
:
<amplify-container *ngIf="authState !== 'signedin'">
<amplify-authenticator></amplify-authenticator>
</amplify-container>
If this is signed in, we can route to a user dashboard component or simply display their username.
<div *ngIf="authState === 'signedin' && user">
// Application Logic
<span>Hello, {{ user.username }}</span>
</div>
This works out of the box and displays a standard SignIn/SignOut interface for users.
The Amplify CLI is responsible for building the necessary modules in the backend to support user authentication, which in this case lives in the AWS cloud. To be more specific, we will use Amazon Cognito, so there is no need to build your own backend.
The config files in the amplify
folder contain these instructions. If you start from scratch, run amplify add auth
to build these files. Then run, amplify push
to deploy them on AWS.
- Read our Authentication documentation to further customize your app. There are many advanced use cases to build upon.
- Join our communities on Twitter and Discord