Rolepath

Authentication Basics

Introduction

Creating users and allowing them to log in and out of your web apps is a crucial functionality that we are finally ready to learn! There is quite a bit of setup involved here, but thankfully none of it is too tricky. You’ll be up and running in no time! In this lesson, we’re going to be using passport.js, an excellent middleware to handle our authentication and sessions for us.

We’re going to be building a very minimal express app that will allow users to sign up, log in, and log out. For now, we’re just going to keep everything except the views in one file to make for easier demonstration, but in a real-world project, it is best practice to split our concerns and functionality into separate modules.


Lesson overview

This section contains a general overview of topics that you will learn in this lesson.

  • Understand the use order for the required middleware for Passport.js.
  • Describe what Passport.js Strategies are.
  • Use the LocalStrategy to authenticate users.
  • Explain the purpose of cookies in authentication.
  • Review prior learning material (routes, templates, middleware, async/await, and promises).
  • Use Passport.js to set up user authentication with Express.
  • Describe what bcrypt is and its use.
  • Describe what a hash is and explain the importance of password hashing.
  • Describe bcrypt’s compare function.