Node.js Passport Login System Tutorial

Web Dev Simplified · 1.1M views · 2019 · 36:28

Open on YouTube

Web developmenttutorialdated

Why Stack Overflow recommends it

Stack Overflow users cite it as the reference tutorial they followed when they hit errors with Passport, bcrypt, method-override and flash messages in the code it teaches.

Recommended by 0 people across 0 different months, 2020 to 2024.

What it is

A 36-minute tutorial by Kyle Cook of Web Dev Simplified that builds a complete login system with Node.js, Express and Passport. It covers bcrypt password hashing, session-based login, protecting routes for logged-in users only, and flash messages.

What people said

Cites 7oS · 2020-04 · Stack Overflow · on “Passport.js code for local stratergy not working correctly for Login module”

So I was trying to implement user authentication for my project by following the video tutorial by "Web Dev Simplified"- [this video] And I've used the exact same code as him(except I've used mysql database to store data, while he used an array). All of the code for registering a user works fine, but the login part doesn't work. All the passport configuration code is written in the passport-config.js file. The problem is that my getUserById function in passport-config.js file doesn't return a user even when there is one in the result returned by the mysql.query() function (I can confirm it because console.log(result[0]) in app.js actually prints the user object). When I console.log(user) in passp

Cites Alessandra Watson · 2021-12 · Stack Overflow · on “Node.js passport.use() function: TypeError: Cannot read properties of undefined (reading 'use')”

I'm following a tutorial on using Node.js and passport for a login system (here: [this video] ) I have downloaded/updated all the libraries many times over so I don't think the passport library is the issue. I've also checked all the variables and they're correct. I think the error is to-do with the authenticateUser being undefined, which is weird because authenticateUser is asynchronous. I've required express, passport and other libraries on another files which also requires this one. Here's the code: const LocalStrategy = require('passport-local').Strategy; const bcrypt = require('bcrypt') function initialize(__passport, getUserByUsername) { const authenticateUser = async (username, password, d

Cites stackneverflow · 2022-02 · Stack Overflow · on “Is it a good idea to override POST request to DELETE in express for logging out?”

I was watching an authentication tutorial by Web Dev Simplified here [this video] . While handling logout requests, the tutorial suggested that we override POST request to DELETE , but did not specify clearly why is it done so. What the tutorial showed was: const methodOverride = require('method-override'); app.use(methodOverride('_method')); app.delete('/logout', (req, res) => { req.logOut(), res.redirect('/login'); }); It also had to modify the logout form to override the POST request like this: <form action="/logout?_method=DELETE" method="POST"> Instead of using all those middlewares and overriding, I could have simply done - app.post('/logout', (req, res) => { req.logOut(), res.redirect('/lo

Cites user13690062 · 2022-03 · Stack Overflow · on “Unknown authentication strategy "local" passport.js”

I keep getting the Error: Unknown authentication strategy "local" error. This is a bit of my main file (server.js): ... app.use(passport.initialize()); app.use(passport.session()); app.use(methodOverride("_method")); ... // Initialize passport const initializePassport = require("./passport-config"); initializePassport( passport, (email) => searchUser({ email: email }), (id) => searchUser({ id: id }) ); ... // Post request - Login user app.post( "/login", checkNotAuthenticated, passport.authenticate("local", { successRedirect: "/", failureRedirect: "/login", failureFlash: true, }) ); this is my passport config file (passport-config.js): const LocalStrategy = require("passport-local").Strategy

Cites TTSPaul · 2022-04 · Stack Overflow · on “I am having issues utilizing NPM commands”

Im currently trying to make a functional log in system for a company website. This is the video im using for reference: [this video] I am unable to get NPM to work for me. i installed node.js and i installed npm by microsoft im now stuck, none of the commands are working for me.

Cites Brian Anderson · 2023-07 · Stack Overflow · on “What is causing a 4 second long delay in "express:router use '/' query"?”

I am trying to learn more about authentication by going through Web Dev Simplified's " Node.js Passport Login System Tutorial [this video] ". I made it through the vid and started adding a few things, but I couldn't help but notice that there was a long (4 second) delay between when I start the server and when it is actually available for connections. I started the express debugger and started lacing my code with console.logs and this is what I get: [LINK] The code looks like this: [LINK] Dependencies are as follows: "dependencies": { "bcrypt": "^5.1.0", "ejs": "^3.1.9", "express": "^4.18.2", "express-flash": "^0.0.2", "express-session": "^1.17.3", "method-override": "^3.0.0", "passport": "^0.6.0

Cites NetCode2020 · 2024-01 · Stack Overflow · on “Using express-flash or connect-flash is resulting in blank messages object”

Here is a video which touches on the same subject and works ok from 25mins...: [this video] I notice here that Kyle uses : return done(null, false, {message:'Password Invalid ...'}) but in your example you are using which includes req.flash..-: return done(null, false, req.flash("error_message", "The email and password...."));