11 - Registration of New Users - Advanced Node and Express - freeCodeCamp
Ganesh H
To create a registration form, in the POST route, we should create the user's document in the database if it doesn't exist, and then authenticate them using their new details.
Link to Challenge : https://www.freecodecamp.org/learn/quality-assurance/advanced-node-and-express/registration-of-new-users Written Guide: https://www.notion.so/ganeshh123/Registration-of-New-Users-95c5dde654c44bc0b84596b0ded5c59a 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:16 - Registration Form 01:08 - POST Route 01:25 - 3 Steps to Registering a User 01:44 - Getting Form Data - bodyParser.urlEncoded() Returns middleware that only parses urlencoded bodies and only looks at requests where the Content-Type header matches the type option. A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body). https://github.com/expressjs/body-parser#bodyparserurlencodedoptions 02:18 - Middleware for Database Work 02:38 - Check if User Already Exists - db.collection.findOne() Returns one document that satisfies the specified query criteria on the collection or view. If multiple documents satisfy the query, this method returns the first document according to the natural order which reflects the order of documents on the disk. https://docs.mongodb.com/manual/reference/method/db.collection.findOne/ 04:34 - Creating a User Document in the Database - db.collection.insertOne() Inserts a single document into MongoDB. If documents passed in do not contain the _id field, one will be added to each of the documents missing it by the driver, mutating the document. http://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#insertOne 06:40 - Logging in the New User - 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 07:32 - Redirecting the User to their Profile 08:40 - Testing the Registration 10:30 - Challenge Solution 16:06 - Explanation of 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 ... https://www.youtube.com/watch?v=APQKQEbZm0M
89313121 Bytes