In the last section, we went ahead and hashed our passwords using bcrypt. We'll now get into our login functionality. We'll use Passport with it, which is an authentication module for Node.js. What's great about Passport is that it's highly customizable; it just gives you a simple layer that sits on top of your application and you can kind of do what you want with it. You can use the LocalStrategy
, which is what we'll be doing. This means we'll have a username, password, and a local database. But you can also use things like Facebook login, Twitter login, and a bunch of other types of logins:
Let's go to the Documentation
page and then go to Authenticate
. This is going to show us that we need a post route to our login and we also need to include this passport.authenticate
:
I'll copy the preceding code and go into routes/users.js
. We'll go down to login. Paste that in right below it and instead of app, we'll use our router, router.post('/login', authenticate
. We...