From the course: Node.js: Securing RESTful APIs
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Add the handlers for login
From the course: Node.js: Securing RESTful APIs
Add the handlers for login
- [Instruction] So the final function that we can use for our user controllers is the login function. So basically allowing to login into the API's and once we're logged in, then we can go ahead and do transactions with the API. So let's go ahead and do that function so we're going to call this log in. So you create a new function and then the arguments again are the request and the response. And then what we're going to do is go ahead and try to find a user in the database. So findOne. So basically, what we need to do is grab the email from the request .body .email. So again in the request, we're going to have an email that we'll try to match to something that we have in our database. So what we'll do and you want to go after the curly brace before the parenthesis, is do a comma and then go ahead and do an error and user and then what we'll do is keep going with a new function to check if there's a new user. So…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.