Integrating User Authentication and Protecting Routes
Learn how to add user authentication functionality in Vue.js application.
Introduction
We have created our frontend UI as well as the backend UI. Now we can integrate and make the frontend function. The process we are going to implement is as follows:
We now have a plan to integrate our backend and frontend. To begin with, we need to install the aws-amplify package. We run the following command to install the AWS Amplify library:
npm install aws-amplify
Once installed, we need to update the ./main.js file with the following:
That is all we have to do to configure our Vue.js application with the AWS Amplify library.
Adding authentication
Let’s begin by creating a folder called lib and creating a file called auth.js. Then we add the following contents:
We now have all the functions that are needed to complete the following actions:
- Register a new user.
- Confirm user email.
- Log in to the application.
- Set up a forgotten password mechanism–this will send a code to the user’s primary email.
- Reset password.
- Provide signout