The next feature you will be adding is authentication.

## Authentication with Amplify

Amplify uses [Amazon Cognito](https://aws.amazon.com/cognito/) as the main authentication provider. Amazon Cognito is a robust user directory service that handles user registration, authentication, account recovery & other operations. In this tutorial, you'll learn how to add authentication to your application using Amazon Cognito and username/password login.

## Create authentication service

```bash
amplify add auth
```

```console
? Do you want to use the default authentication and security configuration? Default configuration
? How do you want users to be able to sign in? Username
? Do you want to configure advanced settings?  No, I am done.
```

To deploy the service, run the `push` command:

```bash
amplify push
```

```console
? Are you sure you want to continue? Y
```

Now, the authentication service has been deployed and you can start using it. To view the deployed services in your project at any time, go to Amplify Console by running the following command:

```bash
amplify console
```

## Create login UI

Now that you have your authentication service deployed to AWS, it's time to add authentication to your Vue app. Creating the login flow can be quite difficult and time consuming to get right. Luckily Amplify has an authentication UI component you can use that will provide the entire authentication flow for us, using your configuration specified in your **aws-exports.js** file.

Open **src/App.vue** and make the following changes.

Within the **App.vue**, add the `authenticator` component:

```html
<script setup>
  import { Authenticator } from '@aws-amplify/ui-vue';
  import '@aws-amplify/ui-vue/styles.css';
</script>
<template>
  <authenticator>
    <template v-slot="{ user, signOut }">
      <h1>Hello {{ user.username }}!</h1>
      <button @click="signOut">Sign Out</button>
    </template>
  </authenticator>
</template>
```

Run the app to see the new Authentication flow protecting the app:

```bash
npm run serve
```

Now you should see the app load with an authentication flow allowing users to sign up and sign in.

In this example, you used the Amplify Vue UI library and the `authenticator` component to quickly get up and running with a real-world authentication flow.

You can also [customize](https://ui.docs.amplify.aws/vue/components/authenticator/customization) this component to add or remove fields, update styling, or other configurations.

In addition to the `authenticator` you can build custom authentication flows using the `Auth` class.

`Auth` has over 30 methods including `signUp`, `signIn`, `forgotPassword`, and `signOut` that allow you full control over all aspects of the user authentication flow. Check out the complete API [here](https://aws-amplify.github.io/amplify-js/api/classes/authclass.html)

In the next section, you'll host your app on the Amplify Console, a hosting service complete with a globally available CDN, atomic deployments, easy custom domains, and CI / CD.
