Learn how to implement a custom user authentication system that controls users access to web resources using Node.js using Express and MongoDB. The system lets users sign up, log in, and log out, limiting access to password-protected resources. Express is a popular web framework for creating MVC applications and RESTful APIs in Node.js. Express lets developers define routes and middleware for submitting and retrieving data in our database. We will leverage the document based NoSQL database, MongoDB, to store our user data by creating a user model with mongoose. Mongoose is an open source Node package for defining data models for an application and connecting to MongoDB.
In this stage we will start by showing the finished project in action then walk through the source code of the starter project. Before diving into the code we will first go over what authentication is and why it is important. We will demystify the authentication process and you will gain an understanding of what is going on behind the scenes when you log into a website. After that we will jump into the code of our project and start working with models and routes.
Chevron 6 steps2:14
3:11
5 questions
2:02
4:53
6 questions
Let’s continue to develop our project by adding routes and views to our Express application. We will use the default templating engine, Jade, to create a registration form. You will also learn how to tie our application into MongoDB using Mongoose, what hashing and salting are, and how they fit into an authentication process. Finally, we will improve our user model with methods and validation while using the Node bcrypt module.
Chevron 11 steps3:52
3:20
7:18
5 questions
4:34
4:44
9:46
5 questions
2:53
5:54
5 questions
Now that we have the logic in place to create and authenticate users, how do we know if the user is logged in? Well, that is where sessions come in. A way of identifying a user will be stored in the session. We will know who the user is as they navigate through the website. Cookies can be used to store this information, and that is what we will show you how to use in this stage.
Chevron 9 steps1:16
2:22
3:28
5 questions
1:39
2:48
7:28
3:53
5 questions
We are almost done with our authentication system! Now that users can register and login and you have sessions to identify the user we need to think about security. Right now anyone that can access the site can navigate to any of the routes whether they are logged in or not. With middleware we can make sure that doesn’t happen.
Chevron 9 steps6:33
2:00
3 questions
3:31
5:48
3:27
4:48
3:42
5 questions