Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed User Authentication With Express and Mongo!
You have completed User Authentication With Express and Mongo!
Preview
In this video add routes to for the application's log in functionality, including a GET route to display the form and a POST route to handle form submissions.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
To provide a way to login,
0:00
we'll need to add a login form, as well
as a way to process the form input.
0:02
We'll need two routes
on the same /login URI.
0:06
One route to display the login form,
0:11
the other to process the login
credentials posted from the form.
0:13
I'll add those routes to the index.js
file inside the routes directory.
0:17
The first route to load
the login form is simple.
0:23
It's similar to the route we added for
the registration form.
0:26
We set up a GET request
along the /login route.
0:29
Then we add a callback function.
0:34
This function will render a pug template.
0:41
We'll build the pug template in the next
video, but you can see that this
0:44
function follows this same structure as
many of the other routes in this file.
0:47
It identifies the name of
the pug template, login,
0:51
and passes along a parameter,
the title of the page.
0:57
Now when the user fills
out the login form,
1:03
the data is posted to the /login route.
1:05
So, let's add a POST route.
1:09
Now, there's gonna be a little bit more
programming required than what I'm
1:13
showing you here.
1:17
We'll need to hash
the submitted password and
1:18
compare that with records
in our Mongo database.
1:21
I'll show you how to do
that a little later.
1:24
So for now,
let's send back a simple message just so
1:26
we can test the route is working.
1:29
The routes are in place, but
we'll need the login form to test them.
1:31
So, in the next video, I'll show you
how to build the login templating form.
1:35
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up