title
Node.js Login System With Passport - Part 3

description
In this video we will add the login functionality using Passport along with a local strategy. We will also implement access control Code For This Series - https://github.com/bradtraversy/loginapp 12 Project Node.js Course: https://www.eduonix.com/affiliates/id/16-10200 Learn Node.js From Scratch Course: https://www.eduonix.com/affiliates/id/16-10033

detail
{'title': 'Node.js Login System With Passport - Part 3', 'heatmap': [{'end': 76.374, 'start': 56.758, 'weight': 0.708}, {'end': 356.127, 'start': 325.302, 'weight': 0.712}, {'end': 475.415, 'start': 459.729, 'weight': 0.722}, {'end': 542.355, 'start': 505.673, 'weight': 1}, {'end': 580.258, 'start': 551.391, 'weight': 0.721}, {'end': 619.806, 'start': 601.845, 'weight': 0.799}], 'summary': 'Learn to implement a login feature with node.js and passport, set up a post route for login, use local strategy for a local database, and redirect to the dashboard upon successful login. also, understand user authentication, model encapsulation, access control, and more for a cleaner application.', 'chapters': [{'end': 161.437, 'segs': [{'end': 25.943, 'src': 'embed', 'start': 0.834, 'weight': 0, 'content': [{'end': 8.057, 'text': 'Hey guys welcome back to part 3 of our login and registration application using Node.js.', 'start': 0.834, 'duration': 7.223}, {'end': 13.478, 'text': 'In the last video we finished up our registration so we can now register a user.', 'start': 8.757, 'duration': 4.721}, {'end': 15.379, 'text': 'Now we need to work on the login.', 'start': 13.919, 'duration': 1.46}, {'end': 25.063, 'text': "Alright, so we're in the passport documentation here and in the authenticate section and you can see that we're creating a post route to login,", 'start': 15.919, 'duration': 9.144}, {'end': 25.943, 'text': "and that's what we want to do.", 'start': 25.063, 'duration': 0.88}], 'summary': 'Developing login functionality using node.js and passport for user authentication.', 'duration': 25.109, 'max_score': 0.834, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/iX8UhDOmkPE/pics/iX8UhDOmkPE834.jpg'}, {'end': 161.437, 'src': 'heatmap', 'start': 56.758, 'weight': 1, 'content': [{'end': 59.98, 'text': 'Now, before we go on to this, we need to actually include passport.', 'start': 56.758, 'duration': 3.222}, {'end': 64.223, 'text': "So up at the top here, I'm just going to paste this in.", 'start': 60.621, 'duration': 3.602}, {'end': 68.205, 'text': "We're including passport as well as local strategy.", 'start': 64.242, 'duration': 3.963}, {'end': 69.906, 'text': 'So get that in there.', 'start': 68.925, 'duration': 0.981}, {'end': 76.374, 'text': "And then down here, we're going to add a parameter to this authenticate.", 'start': 71.952, 'duration': 4.422}, {'end': 79.395, 'text': 'And this is going to be an object.', 'start': 77.895, 'duration': 1.5}, {'end': 81.336, 'text': 'These are basically like options.', 'start': 79.555, 'duration': 1.781}, {'end': 86.258, 'text': 'So we want to set our success.', 'start': 81.957, 'duration': 4.301}, {'end': 90.28, 'text': "I think it's, no, it's not an underscore.", 'start': 88.359, 'duration': 1.921}, {'end': 91.741, 'text': "It's success redirect.", 'start': 90.32, 'duration': 1.421}, {'end': 96.583, 'text': "Okay, that's going to be slash.", 'start': 91.761, 'duration': 4.822}, {'end': 100.545, 'text': "And then we're going to have a failure redirect.", 'start': 97.964, 'duration': 2.581}, {'end': 117.579, 'text': "that's gonna be slash users, slash login, and then we also want to tell it if we want to use flash messaging so say failure flash,", 'start': 103.996, 'duration': 13.583}, {'end': 122.88, 'text': "we're gonna set that to true alright.", 'start': 117.579, 'duration': 5.301}, {'end': 133.851, 'text': "and then down here, all we're gonna do is redirect to the dashboard or slash alright.", 'start': 122.88, 'duration': 10.971}, {'end': 137.993, 'text': "so everything's gonna come from our local strategy which we're going to create.", 'start': 133.851, 'duration': 4.142}, {'end': 150.177, 'text': "now. if we look at the documentation and let's see right here, you see how we have this passport dot, use local strategy,", 'start': 137.993, 'duration': 12.184}, {'end': 158.12, 'text': "we're gonna grab that and we're gonna put that right above our login post, alright.", 'start': 150.177, 'duration': 7.943}, {'end': 161.437, 'text': 'So this does two things.', 'start': 160.276, 'duration': 1.161}], 'summary': 'Configuring passport for local strategy with success and failure redirects, and flash messaging.', 'duration': 109.441, 'max_score': 56.758, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/iX8UhDOmkPE/pics/iX8UhDOmkPE56758.jpg'}], 'start': 0.834, 'title': 'Node.js login & registration', 'summary': 'Outlines the implementation of a login feature using node.js and passport, setting up a post route for login, local strategy for a local database, and redirecting to the dashboard upon successful login.', 'chapters': [{'end': 161.437, 'start': 0.834, 'title': 'Node.js login & registration', 'summary': 'Outlines the process of implementing a login feature using node.js and passport, including setting up a post route for login, including local strategy for a local database, and redirecting to the dashboard upon successful login.', 'duration': 160.603, 'highlights': ['The process of implementing a login feature using Node.js and Passport, including setting up a post route for login, including local strategy for a local database, and redirecting to the dashboard upon successful login.', 'Creating a post route to login and including local strategy for a local database.', 'Setting success and failure redirects for the login, along with enabling flash messaging for failure.', 'Including passport and local strategy for authentication in the login process.']}], 'duration': 160.603, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/iX8UhDOmkPE/pics/iX8UhDOmkPE834.jpg', 'highlights': ['The process of implementing a login feature using Node.js and Passport, including setting up a post route for login, including local strategy for a local database, and redirecting to the dashboard upon successful login.', 'Creating a post route to login and including local strategy for a local database.', 'Setting success and failure redirects for the login, along with enabling flash messaging for failure.', 'Including passport and local strategy for authentication in the login process.']}, {'end': 483.014, 'segs': [{'end': 301.525, 'src': 'embed', 'start': 189.844, 'weight': 0, 'content': [{'end': 198.028, 'text': "All right, so first thing we'll do is we're going to call a model function called getUserByUserName.", 'start': 189.844, 'duration': 8.184}, {'end': 201.049, 'text': "Now we haven't created that yet.", 'start': 199.668, 'duration': 1.381}, {'end': 202.529, 'text': "We'll do that in a second.", 'start': 201.549, 'duration': 0.98}, {'end': 215.275, 'text': "Okay, getUserByUserName and then that's going to be passed in obviously a username and then a function.", 'start': 202.549, 'duration': 12.726}, {'end': 223.108, 'text': "all right, and for this we're going to pass in error and user.", 'start': 218.604, 'duration': 4.504}, {'end': 231.915, 'text': "okay, then we'll check for the error and just throw if there is one.", 'start': 223.108, 'duration': 8.807}, {'end': 235.177, 'text': "if not, then we're going to check to see if there's not a user.", 'start': 231.915, 'duration': 3.262}, {'end': 237.359, 'text': "if there's not a match, all right.", 'start': 235.177, 'duration': 2.182}, {'end': 250.712, 'text': "so we're going to say if not user, then we're going to return done, And we want to say null and the second parameter should be false.", 'start': 237.359, 'duration': 13.353}, {'end': 254.233, 'text': 'And then the third, we can actually include a message.', 'start': 252.032, 'duration': 2.201}, {'end': 261.557, 'text': "So we'll say unknown user.", 'start': 256.935, 'duration': 4.622}, {'end': 265.419, 'text': "Now if there is a user match, it's going to keep going.", 'start': 262.737, 'duration': 2.682}, {'end': 270.121, 'text': 'So the next thing we want to do is call user.comparePassword.', 'start': 265.479, 'duration': 4.642}, {'end': 282.944, 'text': "Okay, so compare password, that's going to get a password, user dot password, and then a function.", 'start': 272.935, 'duration': 10.009}, {'end': 290.651, 'text': "We'll say error and also is match.", 'start': 288.389, 'duration': 2.262}, {'end': 295.235, 'text': "Okay, and then let's check for the error.", 'start': 293.273, 'duration': 1.962}, {'end': 301.525, 'text': "and then we're going to check for the match.", 'start': 299.804, 'duration': 1.721}], 'summary': 'Create function getuserbyusername, check for error and user, return null if no match, compare user password.', 'duration': 111.681, 'max_score': 189.844, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/iX8UhDOmkPE/pics/iX8UhDOmkPE189844.jpg'}, {'end': 483.014, 'src': 'heatmap', 'start': 459.729, 'weight': 3, 'content': [{'end': 461.11, 'text': 'So we want this right here.', 'start': 459.729, 'duration': 1.381}, {'end': 475.415, 'text': 'All right, so bcrypt.compare and we want to pass in the candidate password here.', 'start': 461.13, 'duration': 14.285}, {'end': 483.014, 'text': 'and then the hash, and then I like to call this isMatch.', 'start': 477.672, 'duration': 5.342}], 'summary': 'Using bcrypt.compare to check candidate password against hash.', 'duration': 157.712, 'max_score': 459.729, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/iX8UhDOmkPE/pics/iX8UhDOmkPE459729.jpg'}], 'start': 161.517, 'title': 'User authentication and model encapsulation', 'summary': 'Covers the process and implementation of user authentication in a node.js application, including calling model functions, handling errors, and encapsulating functions in the model for a cleaner application.', 'chapters': [{'end': 261.557, 'start': 161.517, 'title': 'User authentication process', 'summary': 'Discusses the process of user authentication, including calling a model function to validate the username and password and handling potential errors and user matches within the system.', 'duration': 100.04, 'highlights': ['The process involves calling a model function called getUserByUserName to validate the username and password.', 'Handling potential errors and user matches within the system by checking for errors and user existence.', "If there's not a match, the system returns 'null' and a message indicating 'unknown user'."]}, {'end': 392.212, 'start': 262.737, 'title': 'User authentication implementation', 'summary': 'Covers implementing user authentication in a node.js application, including calling user.comparepassword, checking for a match, and creating a function to get a user by username.', 'duration': 129.475, 'highlights': ['Implementing user authentication by calling user.comparePassword and checking for a match to return user data or a false status.', 'Creating a function to get a user by username using a query to match the username and calling user.find1.', 'Explaining the flow of checking for a user match and calling user.comparePassword to validate the password.', "Detailing the process of returning user data if there is a match or returning false with a message if there isn't a match."]}, {'end': 483.014, 'start': 393.041, 'title': 'Encapsulating functions in model', 'summary': 'Discusses encapsulating functions in the model for a cleaner application, including the compare password function using bcrypt to compare candidate passwords with stored hashes.', 'duration': 89.973, 'highlights': ['The chapter emphasizes encapsulating functions in the model for a cleaner application.', 'It discusses the compare password function, which uses bcrypt to compare candidate passwords with stored hashes.']}], 'duration': 321.497, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/iX8UhDOmkPE/pics/iX8UhDOmkPE161517.jpg', 'highlights': ['Calling getUserByUserName to validate username and password', 'Handling errors and user matches by checking for errors and user existence', 'Implementing user authentication by calling user.comparePassword and checking for a match', 'Creating a function to get a user by username using a query to match the username', 'Encapsulating functions in the model for a cleaner application', 'Using bcrypt to compare candidate passwords with stored hashes']}, {'end': 1179.134, 'segs': [{'end': 619.806, 'src': 'heatmap', 'start': 551.391, 'weight': 0, 'content': [{'end': 555.472, 'text': "alright, and that's going to be a function we create inside of our model.", 'start': 551.391, 'duration': 4.081}, {'end': 565.095, 'text': "so let's save that and then go back to the model, and I'm going to copy this okay,", 'start': 555.472, 'duration': 9.623}, {'end': 580.258, 'text': "and this is going to be called get user by ID and that'll take in an ID and then We can get rid of that.", 'start': 565.095, 'duration': 15.163}, {'end': 582.859, 'text': "And then let's change this to find by ID.", 'start': 580.378, 'duration': 2.481}, {'end': 586.34, 'text': 'These are all Mongoose methods that you see here.', 'start': 584.12, 'duration': 2.22}, {'end': 587.401, 'text': 'All right.', 'start': 587.021, 'duration': 0.38}, {'end': 590.502, 'text': 'And then we just have to pass in the ID and call back.', 'start': 587.481, 'duration': 3.021}, {'end': 592.342, 'text': "And that's it.", 'start': 591.822, 'duration': 0.52}, {'end': 595.303, 'text': "So let's say we should now be able to log in, hopefully.", 'start': 592.622, 'duration': 2.681}, {'end': 598.224, 'text': "Let's restart.", 'start': 595.323, 'duration': 2.901}, {'end': 600.265, 'text': 'App is not defined.', 'start': 598.904, 'duration': 1.361}, {'end': 602.266, 'text': 'Oh, oh.', 'start': 601.845, 'duration': 0.421}, {'end': 606.407, 'text': "Since we're using router, this needs to be router.", 'start': 604.126, 'duration': 2.281}, {'end': 611.023, 'text': "All right, let's try again.", 'start': 609.983, 'duration': 1.04}, {'end': 619.806, 'text': "All right, so let's go try to log in.", 'start': 611.043, 'duration': 8.763}], 'summary': "Creating a 'get user by id' function in the model using mongoose methods.", 'duration': 50.875, 'max_score': 551.391, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/iX8UhDOmkPE/pics/iX8UhDOmkPE551391.jpg'}, {'end': 980.307, 'src': 'embed', 'start': 932.497, 'weight': 1, 'content': [{'end': 933.838, 'text': 'If not, we want to see these.', 'start': 932.497, 'duration': 1.341}, {'end': 935.578, 'text': "All right, so let's try that.", 'start': 933.858, 'duration': 1.72}, {'end': 944.04, 'text': "Okay, so we're not logged in.", 'start': 942.099, 'duration': 1.941}, {'end': 948.44, 'text': "You can see that the logout button's not here.", 'start': 944.08, 'duration': 4.36}, {'end': 950.881, 'text': "Now, let's do the same with dashboard actually.", 'start': 948.781, 'duration': 2.1}, {'end': 957.25, 'text': 'Dashboard should only be there if the user is logged in.', 'start': 952.987, 'duration': 4.263}, {'end': 966.897, 'text': 'There we go.', 'start': 966.417, 'duration': 0.48}, {'end': 971.02, 'text': 'Okay So now log in, register.', 'start': 967.137, 'duration': 3.883}, {'end': 971.42, 'text': 'All right.', 'start': 971.14, 'duration': 0.28}, {'end': 972.281, 'text': "So let's log in.", 'start': 971.461, 'duration': 0.82}, {'end': 978.946, 'text': "And now we're logged in so we can see dashboard.", 'start': 976.684, 'duration': 2.262}, {'end': 980.307, 'text': 'We can also see log out.', 'start': 978.986, 'duration': 1.321}], 'summary': 'Testing revealed issues with login and dashboard functionality. upon logging in, the dashboard and logout options became accessible.', 'duration': 47.81, 'max_score': 932.497, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/iX8UhDOmkPE/pics/iX8UhDOmkPE932497.jpg'}], 'start': 484.734, 'title': 'User authentication and access control', 'summary': "Covers implementing user authentication using serialize and deserialize functions, replacing mongoose methods, creating a new 'get user by id' function, and implementing access control for login, logout, and dashboard functionality using node.js and router.", 'chapters': [{'end': 602.266, 'start': 484.734, 'title': 'Implementing user authentication', 'summary': "Covers implementing user authentication using serialize and deserialize functions, replacing mongoose methods in the route file, and creating a new 'get user by id' function in the model, with a focus on code modifications and error checking.", 'duration': 117.532, 'highlights': ["The chapter covers implementing user authentication using serialize and deserialize functions, replacing Mongoose methods in the route file, and creating a new 'get user by ID' function in the model, with a focus on code modifications and error checking.", "Replacing Mongoose methods in the route file with a new 'get user by ID' function results in improved user authentication and potentially faster user retrieval.", 'The need for serialize and deserialize functions for user authentication is highlighted, emphasizing the importance of these functions in handling user data and login functionality.', "The process involves modifying code to replace 'find by id' with 'get user by ID' and checking for errors, showcasing the attention to detail in ensuring accurate implementation of user authentication."]}, {'end': 1179.134, 'start': 604.126, 'title': 'Implementing user authentication and access control', 'summary': 'Demonstrates the implementation of user authentication and access control through the creation of login, logout, and dashboard functionality using node.js and router, ensuring a secure and seamless user experience.', 'duration': 575.008, 'highlights': ['Implemented login functionality for users, including error handling for missing credentials and invalid password, with a successful login message. The implementation of login functionality includes error handling for missing credentials and invalid password, ensuring a secure login process.', 'Created a logout functionality with a success message and redirection to the login page. The creation of a logout functionality with a success message and proper redirection ensures a seamless logout process for users.', "Implemented access control by dynamically displaying login, register, dashboard, and logout links based on the user's login status. The dynamic display of login, register, dashboard, and logout links based on the user's login status ensures proper access control and enhances user experience."]}], 'duration': 694.4, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/iX8UhDOmkPE/pics/iX8UhDOmkPE484734.jpg', 'highlights': ["The chapter covers implementing user authentication using serialize and deserialize functions, replacing Mongoose methods in the route file, and creating a new 'get user by ID' function in the model, with a focus on code modifications and error checking.", "Implemented access control by dynamically displaying login, register, dashboard, and logout links based on the user's login status. The dynamic display of login, register, dashboard, and logout links based on the user's login status ensures proper access control and enhances user experience.", "Replacing Mongoose methods in the route file with a new 'get user by ID' function results in improved user authentication and potentially faster user retrieval.", 'The need for serialize and deserialize functions for user authentication is highlighted, emphasizing the importance of these functions in handling user data and login functionality.']}], 'highlights': ['The process of implementing a login feature using Node.js and Passport, including setting up a post route for login, including local strategy for a local database, and redirecting to the dashboard upon successful login.', "Implemented access control by dynamically displaying login, register, dashboard, and logout links based on the user's login status. The dynamic display of login, register, dashboard, and logout links based on the user's login status ensures proper access control and enhances user experience.", "Replacing Mongoose methods in the route file with a new 'get user by ID' function results in improved user authentication and potentially faster user retrieval.", 'Creating a post route to login and including local strategy for a local database.', 'Setting success and failure redirects for the login, along with enabling flash messaging for failure.', 'The need for serialize and deserialize functions for user authentication is highlighted, emphasizing the importance of these functions in handling user data and login functionality.', 'Encapsulating functions in the model for a cleaner application', 'Using bcrypt to compare candidate passwords with stored hashes', 'Calling getUserByUserName to validate username and password', 'Handling errors and user matches by checking for errors and user existence', 'Implementing user authentication by calling user.comparePassword and checking for a match', 'Creating a function to get a user by username using a query to match the username', 'Including passport and local strategy for authentication in the login process.', "The chapter covers implementing user authentication using serialize and deserialize functions, replacing Mongoose methods in the route file, and creating a new 'get user by ID' function in the model, with a focus on code modifications and error checking."]}