07 - How to Use Passport Strategies - Advanced Node and Express - freeCodeCamp
Ganesh H
To link login forms to our strategies, we can mount a middleware called passport.authenticate() to our POST route.
Link to Challenge : https://www.freecodecamp.org/learn/quality-assurance/advanced-node-and-express/how-to-use-passport-strategies Written Guide: https://www.notion.so/ganeshh123/How-to-Use-Passport-Strategies-b37474d0b8a34d25b207034f8c965d19
Full Playlist for this course : https://www.youtube.com/playlist?list=PLhGp6N0DI_1RL9djhgSH65pZhJ6xSyKX8 All Writen Guides for this course : https://www.notion.so/ganeshh123/ccf6039186334f83a54c1c9216f30e3c All My Tutorials can be found at : https://www.notion.so/Tutorials-Ganesh-H-293ea420d34a464f9a1907e0405b5f26
00:00 - Introduction 00:12 - Login Form Setup 00:55 - Creating a User Account Document for Testing 01:27 - Setting up a POST route 01:49 - Getting Form Data with Body Parser - bodyParser.urlencoded() Returns middleware that only parses urlencoded bodies and only looks at requests where the Content-Type header matches the type option. This parser accepts only UTF-8 encoding of the body and supports automatic inflation of gzip and deflate encodings. A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body). This object will contain key-value pairs, where the value can be a string or array (when extended is false), or any type (when extended is true). https://github.com/expressjs/body-parser#bodyparserurlencodedoptions 02:37 - Mounting the Strategy - passport.authenticate() This function returns a middleware which runs the strategies. If one of the strategies succeeds, this will set req.user. If you pass no options or callback, and all strategies fail, this will write a 401 to the response. https://github.com/jwalton/passport-api-docs#passportauthenticatestrategyname-options-callback 05:12 - Where the User's Details can be found 05:36 - Correction/Tweak for MongoDB Database Connection 06:35 - Testing the Login 07:18 - Rendering Page with User Details - response.render() Renders a view and sends the rendered HTML string to the client. https://expressjs.com/en/api.html#res.render 08:20 - What Happens When Authentication Fails 09:00 - How This Works 10:10 - Challenge Solution
-————————————————————————————————————- Node.js is an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside a web browser. Node.js lets developers use JavaScript to write command line tools and for server-side scripting—running scripts server-side to produce dynamic web page content before the page is sent to the user's web browser.
Express.js, or simply Express, is a web application framework for Node.js. It is designed for building web applic ... https://www.youtube.com/watch?v=ts1SU3J39OY
72333850 Bytes