04 - Serialization of a User Object - Advanced Node and Express - freeCodeCamp
Ganesh H
Serializaton and Deserialization allow us to reduce our User objects into a small piece of information which we can efficiently store into a cookie.
Link to Challenge : https://www.freecodecamp.org/learn/quality-assurance/advanced-node-and-express/serialization-of-a-user-object Written Guide: https://www.notion.so/ganeshh123/Serialization-of-a-User-Object-945e3c57bc144e07a96fca87f6230ce1
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:30 - MongoDB Installation 01:10 - Serialize Function - passport.serializeUser() Passport will call this to serialize the user to the session whenever you login a user with req.login(), or whenever a user is authenticated via passport.authenticate(). The function you pass in should call done(null, serializedUser). What this is going to do is set req.session.passport.user = serializedUser. https://github.com/jwalton/passport-api-docs#passportserializeuserfnuser-done--fnreq-user-done 04:06 - Deserialize Function - passport.deserializeUser() Passport will call this to deserialize the user from the session. Should call done(null, user). The serializedUser is req.session.passport.user. https://github.com/jwalton/passport-api-docs#passportdeserializeuserfnserializeduser-done--fnreq-serializeduser-done 05:05 - Getting the User Document from the database - 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/ 09:02 - 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 applications and APIs. It has been called the de facto standard server framework for Node.js. Express runs between the server created by Node.js and the frontend pages of a web application. Express also handles an application's routing.
freeCodeCamp (also referred t ... https://www.youtube.com/watch?v=gYqR-pf1EGQ
51458095 Bytes