From the course: Building Vue and Node Apps with Authentication

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating the login services

Creating the login services

From the course: Building Vue and Node Apps with Authentication

Start my 1-month free trial

Creating the login services

- [Instructor] In this video, we'll implement the login endpoint. I'll begin by copying the register endpoint and pasting it below. Then let's rename it. We will no longer be getting register data, but instead login data, so I'll make that change to line 43, and we will no longer need to push a new user, so I'll take out line 45. We will still need to get the user ID, but we'll need a different method for getting that, and what we'll do is simply search through our users list to see if there's a username that matches what we have in our login data. After that, all we need to do is check if the passwords match, so I'll use users.findIndex, since the index will give us the user ID. And in here, we'll pass in an inline arrow function that will provide our search. So we'll use user arrow, and then check user.userName. If it matches, loginData.userName. Since this is a bit complex, let's test this out with a console.log. Let's save this and give it a try. So we could register a new user…

Contents