Node.js Passport Login System Tutorial

preview_player
Показать описание
User authentication and login is the most important feature of many websites, and most likely a key component to your next project. In this video I will be covering absolutely everything you need to know about user login and authentication in the most concise and simple way. We will be using Express for our server backend and Passport to help us manage the logged in state of users. We will also be sure to properly encrypt and hash all user passwords so that our application is completely secure. By the end of this video you will have built a fully functional login system that you can use in any of your future projects.

📚 Materials/References:

🧠 Concepts Covered:

- How to encrypt user passwords
- Restricting access to routes to only logged in users

🌎 Find Me Here:

#PassportLogin #WDS #NodejsLogin
Рекомендации по теме
Комментарии
Автор

First you show what we're gonna do, then you teach how to get there. Excellent! This is one of my top 5 favorite dev channels.

eduardopassero
Автор

4:47 tell express to use ejs view engine.
9:49 express url encoded to access data from HTML form.
12:03 bcrypt hash password from post /register.
17:01 use "strategy" for local version passport.
18:42 & 27:55 passport serializeUser & deserializeUser.
19:41 & 28:10 passport done function.
20:36 bcrypt compare hash to authenticate user.
22:45 app.use flash.
23:15 - 24:41 app.use session.
23:57 require dotenv config.
24:41 app.use passport initialize & session.
25:05 passport.authenticate middleware in post/login to redirect if the user is authenticated or not.
25:30 failureFlash to send the error messages to ejs.
25:46 display errors on ejs.
27:10 error fix: pass in authenticateUser to localStrategy.
29:20 get username from passport.
30:13 protect home route from not logged in users.
31:49 prevent already logged users from logged in.
33:27 set up log out route.
34:17 method-override allow delete verb for html.
34:58 method-override html form url/action string.
35:51 error fix: res.redirect.

flowerofash
Автор

Finally someone that's straight to the point, without stopping 2 hours every time to explain EJS or some basic stuff. THANK YOU!

tahasalim
Автор

I found this being one of the few rare tech channels where 0.75x speed works the best rather than 1.25x. Thanks man.

alfredliu
Автор

33:44 - Since passport version 0.6.0 (which was released only a few days ago by the time of writing this), req.logout is asynchronous.

You will get the error: "req#logout requires a callback function."
To fix it, all you need to do is replace this:

app.delete('/logout', (req, res) => {
  req.logOut();
  res.redirect('/login');
});



By this:

app.delete('/logout', (req, res, next) => {
req.logOut((err) => {
if (err) {
return next(err);
}
res.redirect('/login');
});
});

NumbersOficial
Автор

I was feeling learning javascript/node was an impossible thing for its very versatility. After 1 hour watching your video, feel so confident I can conquer it now. Thank you!

youngfella
Автор

!!This channel is seriously underrated!!
I mean your content is sooo 🔥🔥🔥

theemacsen
Автор

Even though it took me 2 viewings to understand passport, I loved how complete this tutorial was, while also only focusing on the core functionality without any fluff. Thank you so much, Kyle, for valuing the viewer's time. 😊

nsharma
Автор

1:42 - Installing express, ejc
2:05 - Installing nodemon, dotenv
2:56 - Creating first script
11:10 - Installing bcrypt
14:39 - Installing passport, passport-local, express-session, express-flash
34:17 - Installing method-override

PS: I wrote this comment just to remind myself of the times for each step in the video that was of interest to me, but as it has helped other people, it needs updates to be more complete. Anyone who can help, please reply to this comment.

PS 2: For a more secure environment, if some user send his email or password wrong at login, just warn that one of both is wrong, but don't specify which one.

kmbcg
Автор

To tell the truth Kyle, 6 months ago when i was a noob, i could not understand your explanations. Now they are build mid level projects for company interviews, and I know some javascript, you are trully helpfull.

ArisAris-fsip
Автор

Thanks to Kyle for this tutorial. If recently you are watching this tutorial you might get and error: "req#logout requires a callback function, " when you try to logout. This error occurs because the req.logout() function requires a callback function in more recent versions of passport. Here's how you can modify the app.delete('/logout', ...) route to include a callback function:
app.delete('/logout', (req, res) => {
req.logout((err) => {
if (err) {
return next(err);
}
res.redirect('/login');
});
});

hammedakindunbi
Автор

I wish every programming tutorials channel would teach like this. Telling the end result and then explaining everything from 0 is the best way to understand how things work, and since we can follow the code and apply it right away, it also keeps me motivated to continue learning.

Evokus
Автор

Absolutely no BS. straight to the point as always Kyle. Great work and a great channel to follow for the devs.

rajeshseptember
Автор

i saw this tutorial a few days ago... i really struggled getting it.. i went crazy watching so many videos, reading stack overflow answers and so many days after, return to this and really quite got it all...
for all those out there going nuts with this things, patience.. your actions will reward you, but you have to do the work

jamiroquaiordie
Автор

Yo im glad I bumped into this channel, best tutorials, strait to the point!

CsTrGaming
Автор

I just have switched from php to node js for 2 weeks. Your training is first class. Very helpful. THANK YOU VERY MUCH.

shoeshiner
Автор

as a beginner took me some time to figure some things out, but finally completed this and got to learn a lot out of it. thanks for this amazing tutorial :)

ShivamAgrawal
Автор

All details in single shot without break. That's amazing.

deeppatel
Автор

Love your channel, Kyle! I'm entering my second year in the industry and have only found a few good channels among the many rest. I love how you write and explain in the manner that the developing flows. It's like artistry... much like my beloved original trainer. I'll be binging and learning with you for a while, so thank you! 💖

guayadepew
Автор

This video is terrific. Lucid. Concise. To the point. Having watched maybe a dozen videos on passport, this is the best.

cgoodwin