From the course: React: Authentication

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Adding a log-in route to the server

Adding a log-in route to the server - React.js Tutorial

From the course: React: Authentication

Adding a log-in route to the server

- [Instructor] All right, so now that we've created a signup route, let's do the same thing but with a login route. So the login route's going to look pretty similar to the signup route here. The main difference is that instead of creating the new user, like we did up here, we're just going to be loading that user out of the database and checking to make sure that their password is correct. So here's what this is going to look like. All right, we'll leave the signup route up at the top because that's the first part of the flow generally. So here's what this will look like. We'll say app.post, we're going to have this be a post route again, and the path for this is going to be /api/login. And then for the handler, we're going to say request and response. And we'll start off here by getting the email and password off the request body, just like in the signup route, all right? And the next thing we're going to do is we're going to load the user from the database. So all we need to do for…

Contents