Building Node.js Authentication from Scratch

  Рет қаралды 114,291

Piyush Garg

Piyush Garg

Жыл бұрын

► Master NodeJS Playlist: • Master NodeJS
► Source Code: github.com/piyushgargdev-01/s...
In this tutorial video, you will learn how to create a secure and robust authentication system for your Node.js application from scratch. We will cover the basics of user authentication and authorization and show you how to implement login and registration functionality using Node.js and MongoDB.
► Complete Full Stack Web Developer RoadMap 2023: • Complete Full Stack We...
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows developers to run JavaScript on the server side, creating server-side applications with JavaScript.
► My Website: www.piyushgarg.dev
My Gears
► My Girlfriend: amzn.to/3WD6FRp
► Apple MacBook Laptop: amzn.to/3WBJgQn
► Anker USB Hub: amzn.to/3GhZSr0
► Blue Yeti Microphone: amzn.to/3YKZ9FT
► External 27” Monitor: amzn.to/3Vp3xaO
► Logitech MK295 Wireless Keyboard and Mouse: amzn.to/3DuL1bB
► Seagate Expansion 1TB External HDD: amzn.to/3QMm5Q8
► Tripod: amzn.to/3S4OwK4
► Ring Light: amzn.to/3YLf8DR
Disclaimer: All the links above are affiliate links.
Social Links
► Twitter - / piyushgarg_dev
► LinkedIn - / piyushgarg195
Video Titles
Securing Your Node.js App with User Authentication
Authentication 101: Implementing Login in Node.js
Adding User Login to Your Node.js Application
Authentication in NodeJS
Tags
#nodejs #authentication #javascript #expressjs #mongodb #mernstack #developer #api #https #server #javascriptinhindi #webdevelopment #webapp #realtimeapp #serverside #nonblockingio #tech

Пікірлер: 104
@iamakashkumarram
@iamakashkumarram Жыл бұрын
This is the best NodeJS series ever made.
@not_amanullah
@not_amanullah 3 ай бұрын
agreed 💯
@kanikamehrotra1518
@kanikamehrotra1518 10 ай бұрын
Thankyou so much for the wonderful playlist.
@AkshaySharma-bg3oj
@AkshaySharma-bg3oj 6 ай бұрын
Thanks a lot for availing this series for free, we know it takes hell amount of your time. Thanks mate.
@varmapurushotham
@varmapurushotham Ай бұрын
Enjoyed the entire video! Lot of learning! Thank you :)
@ankit1153
@ankit1153 11 ай бұрын
Thank you sir i don't know about how to find data in other collection by user ID but after watching this video i am clear now...
@iamakashkumarram
@iamakashkumarram Жыл бұрын
Sir please cover JWT Authentication and Local Storage in depth.
@VarunSharma-xd8xd
@VarunSharma-xd8xd Ай бұрын
when i saw this playlist for first time i was frustrated but now i am able to grasp the concepts
@iUmerFarooq
@iUmerFarooq Жыл бұрын
Bohot acha sa samjatha ho. Make more projects in Nodejs/Expressjs. Bohot Shukriya
@KrishnaKumar-kh5iu
@KrishnaKumar-kh5iu 4 ай бұрын
🎯 Key Takeaways for quick navigation: 00:00 🛠 *Node.js Authentication Basics* - Introduction to authentication patterns in Node.js. - Two basic patterns discussed: Stateful and Stateless authentication. 01:07 🚗 *Authentication Analogy: Parking Ticket* - Illustration of stateful authentication using a parking attendant analogy. - Comparison between providing a parking ticket and receiving a unique ID for server-side data maintenance. 02:02 🎟 *Stateless Authentication: Diary Entry* - Explanation of stateless authentication using the example of a parking ticket without server-side data storage. - Analogous process of generating and validating unique IDs for accessing resources. 03:38 🔄 *Transition to Server-Side Authentication* - Transition from client-side to server-side authentication process. - Example of a client sending a request with user credentials to the server for authentication. 04:09 📝 *Server-side session management* - Understanding session IDs and their management on the server-side, - Sending session IDs along with requests for server authentication, - Utilizing cookies or headers for transferring unique IDs and managing authentication. 06:02 🛠 *Implementing authentication in the application* - Setting up authentication middleware in the Express application, - Validating tokens and unique IDs for authentication, - Incorporating user data and authentication parameters into the application model. 08:52 🛠 *Creating Authentication Routes* - Setting up authentication routes in Node.js. - Creating a user model and defining routes for signup. - Implementing controller functions for user signup. 10:13 📝 *User Signup Validation* - Validating user input such as password length and email format. - Handling user signup requests and responses. - Importing user model and returning appropriate responses. 11:50 📲 *Handling User Registration* - Implementing registration functionality for users. - Defining routes and handling user registration requests. - Creating user signup forms with input validation. 14:17 🛠 *Handling user sign-up form submission* - Understanding form action and method, - Troubleshooting form submission errors and refreshing the page. 16:04 🔑 *Ensuring successful user registration process* - Configuring form redirection after successful registration, - Implementing conditional logic for user access based on authentication status. 17:11 🚦 *Validating user credentials and redirecting* - Validating user input for email and password, - Implementing error handling and redirecting based on authentication status. 20:07 🛠 *Node.js Authentication Setup* - Setting up authentication process in Node.js, - Generating unique session IDs, - Installing necessary packages and importing them. 21:32 🍪 *Cookie Generation and Handling* - Creating and handling cookies for user sessions, - Utilizing middleware to retrieve cookie values, - Implementing functionality to refresh cookies upon server request. 22:59 📝 *Application Diary and Control Flow* - Demonstrating control flow within the application, - Logging user activities in the application diary, - Managing user sessions and associated data. 24:56 🔒 *Middleware Function for User Authentication* - Implementing middleware function for user authentication, - Accessing user ID from cookies, - Handling redirection based on user authentication status. 27:55 🍪 *Cookie Parsing and Validation* - Parsing and validating cookies for user authentication, - Ensuring proper access control based on URL paths, - Handling cookie-related errors gracefully. 29:02 🛠 *Troubleshooting and Debugging* - Debugging cookie reading and generation issues, - Resolving errors related to undefined properties, - Iterative debugging process for smoother development. 30:27 🛠 *Node.js Authentication Implementation* - Implementing password generation and authentication in Node.js. - Discussion on server restart issues affecting data integrity. - Handling URL generation and user identification securely. 31:48 🔄 *URL Generation and Data Integrity* - Addressing data integrity challenges upon server refresh. - Ensuring correct URL generation and user identification after server restart. - Implementing strategies to maintain data consistency and user authentication. 33:19 🖥 *Dynamic URL Handling and User Identification* - Exploring middleware for dynamic URL handling and user identification. - Adding user-specific references to generated URLs. - Utilizing user IDs for personalized URL management and authentication. 34:44 🔒 *Implementing authentication logic* - Creating middleware function to check authentication status. - Simplifying authentication logic by restricting access. - Handling authentication checks and redirects efficiently. 36:07 🧳 *Setting up user authentication* - Creating a sign-up form with fields for full name, email, and password. - Generating and validating short IDs for user authentication. - Implementing basic authentication workflow and URL handling. 37:57 🚪 *Customizing user access and permissions* - Limiting user access to their own analytics and URLs. - Generating short IDs for user-specific data access. - Ensuring secure and controlled authentication processes.
@pranjalmaurya3832
@pranjalmaurya3832 4 ай бұрын
hey! do you faced the same problem at 29:00 i.e. not being able to generate short urls after login?
@Solo_playz
@Solo_playz 3 ай бұрын
Bhai video se jyada heavy Tera comment hai ☠️
@whyDude123
@whyDude123 2 ай бұрын
@@Solo_playz Ai se generated hai
@IamMQaisar
@IamMQaisar Ай бұрын
@@whyDude123 🤣
@imPrathamDev
@imPrathamDev Жыл бұрын
First time I see Gravity Falls and Adventure Time crossover
@ratishjain2718
@ratishjain2718 6 ай бұрын
Best Nodejs series out there and I am not even kidding how good he teaches
@rishabhraj8233
@rishabhraj8233 6 ай бұрын
yes man @piyush Garg is a god sent man
@mujibulhaquetanim
@mujibulhaquetanim 5 ай бұрын
But don't think that's a full series on Node.js; he covered it yesterday in his live stream.
@Ayush37262
@Ayush37262 5 ай бұрын
​@@mujibulhaquetanim Complete nhi hai kya ye??
@mujibulhaquetanim
@mujibulhaquetanim 5 ай бұрын
This playlist is still suitable for beginners, even though there are still some gaps in the graphql series. He nearly covered every essential topic related to Node.js.@@Ayush37262
@mma-dost
@mma-dost Жыл бұрын
Great video bhaiya !! Please make more videos asap
@arbabmemon2095
@arbabmemon2095 8 ай бұрын
You have been doing great job sir
@ASHISHKUMAR-de9jn
@ASHISHKUMAR-de9jn Жыл бұрын
Thank you sir ❤
@polymath-403
@polymath-403 Жыл бұрын
Thanks Buddy
@easelogic
@easelogic 6 күн бұрын
Best Series. 👩🏻‍💻👩🏻‍💻
@inlifegadgets
@inlifegadgets Жыл бұрын
Great Video Thanks Sir
@piyushgargdev
@piyushgargdev Жыл бұрын
Most welcome
@webdeveloper3529
@webdeveloper3529 Жыл бұрын
Wow i cleared my all concepts 😎
@piyushgargdev
@piyushgargdev Жыл бұрын
Great 🚀
@gamingwithasmile268
@gamingwithasmile268 Жыл бұрын
Thanks sir❤
@pabloescobar.exe.
@pabloescobar.exe. 10 ай бұрын
Hey piyush, can u make videos on styling web pages using tailwind css Or just css, in UI
@rohitghadage3220
@rohitghadage3220 11 ай бұрын
Sir setting user details in cookies would be done with express-session by default right?
@SulavGhimireeee
@SulavGhimireeee 6 ай бұрын
Thanks bro
@sahildhanawade
@sahildhanawade 10 ай бұрын
my doubt apne sessionIdToUserMap object me user ki uid or user ki details store ki hai pr ek time ke baad ye server ki bhot memory kha jayega to es object me se hr user ki details ek time ke baad apne aap delete ho jana chahiye
@coolcoder-bh9ic
@coolcoder-bh9ic 8 ай бұрын
SIr on deployment why user persistence not there ? means after one time logged in in any device i can generate url in another device also without logged in ?
@fun3.1
@fun3.1 18 күн бұрын
nicely explain
@MetroExodus999
@MetroExodus999 Ай бұрын
good job bro
@ShivendraPratap524
@ShivendraPratap524 Жыл бұрын
sir thanks for the awesome content , but i have a request that please try to explain things , for ex : cookies , etc please , it would help us understand more easily
@piyushgargdev
@piyushgargdev Жыл бұрын
Noted
@shivanshsrivastava5561
@shivanshsrivastava5561 4 ай бұрын
​@@piyushgargdevafter loggin with email and password we are redirected to page to generate shortUrl or shortId but when I enter original url after loggin I am being redirected back to loggin page ,,unable to resolve
@sarfaraz_adil
@sarfaraz_adil 2 күн бұрын
@@shivanshsrivastava5561 hii same problem bro can you please help me
@indrajitnaskar6851
@indrajitnaskar6851 4 ай бұрын
I clone your code ,but the urls that user visited is not working, both users data is showing, please some one help me
@sparsh-0384
@sparsh-0384 7 ай бұрын
Well explained... Where I can get the code for reference
@thebishalpaul
@thebishalpaul 11 ай бұрын
Understood everything except checkAuth at 35:22 tried using restrictToLoggedInOnly middleware instead of checkAuth the home page redirects to login page but it doesn't load. Can anyone plz help why is it so?
@shubham0546
@shubham0546 5 ай бұрын
Same issue
@Ayush37262
@Ayush37262 5 ай бұрын
What do you mean by "it doesn't load"?? Can you explain in detail...
@thebishalpaul
@thebishalpaul 11 ай бұрын
Bhaiya can you plz describe why are we again getting user and checking if user exists (line 8 at 29:14) as, if the user isn't logged in then the UID won't be generated so the first check serves the purpose isn't it? Edit: Found out that on refresh the map obj doesn't reset but on server restart it does. For which the second check is important. Keeping the comment might help someone with same doubt.
@ombandurkar7950
@ombandurkar7950 7 ай бұрын
Thank you for keeping the comment, it helped me
@thebishalpaul
@thebishalpaul 7 ай бұрын
@@ombandurkar7950 happy to help 🙂
@sarfaraz_adil
@sarfaraz_adil 2 күн бұрын
@@thebishalpaul after loggin with email and password we are redirected to page to generate shortUrl or shortId but when I enter original url after loggin I am being redirected back to loggin page ,,unable to resolve can you help me please
@ibntofajjal
@ibntofajjal Жыл бұрын
Damn Bro!
@SUMITDAS-tf7jh
@SUMITDAS-tf7jh 11 ай бұрын
bhaiya email authentication ka bhi ek video plz bana dena with forget fassword 😊😊
@lovelymusic3549
@lovelymusic3549 Жыл бұрын
Sir when react JS course is coming any idea sir?
@fearwayesloot
@fearwayesloot 4 ай бұрын
Bhaiya if middle man proxy use karega he will get our api how we secure
@lucifer.morningstar9523
@lucifer.morningstar9523 3 ай бұрын
What if we want to pass the data to frontend like react app instead of .ejs views files How to do it ?
@PubG-dl5eh
@PubG-dl5eh Жыл бұрын
Osm series💥 But can you add the complete authentication like.... Sign up Otp verify Email verify Login ......etc
@piyushgargdev
@piyushgargdev Жыл бұрын
Sure
@vikashgupta3305
@vikashgupta3305 3 ай бұрын
just WOOWWWWW
@sheikhumaid9213
@sheikhumaid9213 2 ай бұрын
Is this process production ready?
@dethaliyayashhimatbhai6170
@dethaliyayashhimatbhai6170 16 сағат бұрын
Bro he already explained in his previous videos
@UserNotFound-py5eg
@UserNotFound-py5eg 8 ай бұрын
Can you make a proper video on 'How to create a chrome extension' Please
@AtulKumar-pi2ky
@AtulKumar-pi2ky Жыл бұрын
Please create a video on google-reCaptcha v2 verification in a registration form to avoid scripting much need and it is not available on any channel where an API is made for that please please make it if possible
@AbhishekRaut0001
@AbhishekRaut0001 Ай бұрын
Key Takeaways for quick navigation: 00:00 Node.js Authentication Basics - Introduction to authentication patterns in Node.js. - Two basic patterns discussed: Stateful and Stateless authentication. 01:07 Authentication Analogy: Parking Ticket - Illustration of stateful authentication using a parking attendant analogy. - Comparison between providing a parking ticket and receiving a unique ID for server-side data maintenance. 02:02 Stateless Authentication: Diary Entry - Explanation of stateless authentication using the example of a parking ticket without server-side data storage. - Analogous process of generating and validating unique IDs for accessing resources. 03:38 Transition to Server-Side Authentication - Transition from client-side to server-side authentication process. - Example of a client sending a request with user credentials to the server for authentication. 04:09 Server-side session management - Understanding session IDs and their management on the server-side, - Sending session IDs along with requests for server authentication, - Utilizing cookies or headers for transferring unique IDs and managing authentication. 06:02 Implementing authentication in the application - Setting up authentication middleware in the Express application, - Validating tokens and unique IDs for authentication, - Incorporating user data and authentication parameters into the application model. 08:52 Creating Authentication Routes - Setting up authentication routes in Node.js. - Creating a user model and defining routes for signup. - Implementing controller functions for user signup. 10:13 User Signup Validation - Validating user input such as password length and email format. - Handling user signup requests and responses. - Importing user model and returning appropriate responses. 11:50 Handling User Registration - Implementing registration functionality for users. - Defining routes and handling user registration requests. - Creating user signup forms with input validation. 14:17 Handling user sign-up form submission - Understanding form action and method, - Troubleshooting form submission errors and refreshing the page. 16:04 Ensuring successful user registration process - Configuring form redirection after successful registration, - Implementing conditional logic for user access based on authentication status. 17:11 Validating user credentials and redirecting - Validating user input for email and password, - Implementing error handling and redirecting based on authentication status. 20:07 Node.js Authentication Setup - Setting up authentication process in Node.js, - Generating unique session IDs, - Installing necessary packages and importing them. 21:32 Cookie Generation and Handling - Creating and handling cookies for user sessions, - Utilizing middleware to retrieve cookie values, - Implementing functionality to refresh cookies upon server request. 22:59 Application Diary and Control Flow - Demonstrating control flow within the application, - Logging user activities in the application diary, - Managing user sessions and associated data. 24:56 Middleware Function for User Authentication - Implementing middleware function for user authentication, - Accessing user ID from cookies, - Handling redirection based on user authentication status. 27:55 Cookie Parsing and Validation - Parsing and validating cookies for user authentication, - Ensuring proper access control based on URL paths, - Handling cookie-related errors gracefully. 29:02 Troubleshooting and Debugging - Debugging cookie reading and generation issues, - Resolving errors related to undefined properties, - Iterative debugging process for smoother development. 30:27 Node.js Authentication Implementation - Implementing password generation and authentication in Node.js. - Discussion on server restart issues affecting data integrity. - Handling URL generation and user identification securely. 31:48 URL Generation and Data Integrity - Addressing data integrity challenges upon server refresh. - Ensuring correct URL generation and user identification after server restart. - Implementing strategies to maintain data consistency and user authentication. 33:19 Dynamic URL Handling and User Identification - Exploring middleware for dynamic URL handling and user identification. - Adding user-specific references to generated URLs. - Utilizing user IDs for personalized URL management and authentication. 34:44 Implementing authentication logic - Creating middleware function to check authentication status. - Simplifying authentication logic by restricting access. - Handling authentication checks and redirects efficiently. 36:07 Setting up user authentication - Creating a sign-up form with fields for full name, email, and password. - Generating and validating short IDs for user authentication. - Implementing basic authentication workflow and URL handling. 37:57 Customizing user access and permissions - Limiting user access to their own analytics and URLs. - Generating short IDs for user-specific data access. - Ensuring secure and controlled authentication processes.
@Akshay-be3xt
@Akshay-be3xt 2 ай бұрын
can someone please share me code ...i have write but getting error...
@bm9code
@bm9code 6 ай бұрын
how setUser is able to get the value stored getUser even after reloding page
@bm9code
@bm9code 6 ай бұрын
solution will be given in next video 38:45
@samad8906
@samad8906 3 ай бұрын
It would have been better if u would use postman or any server client
@amitkumarlkr
@amitkumarlkr 4 ай бұрын
Done, Done, Done, Done..... 😂😂😂
@zeta_meow_meow
@zeta_meow_meow Жыл бұрын
github code is not working home.ejs file mai (urls) giving error
@saubhagyalive3061
@saubhagyalive3061 11 ай бұрын
same man !! did u find the solution ? also the redirectURL in index is also giving error to me
@ajiteshmishra0005
@ajiteshmishra0005 2 ай бұрын
Is this called JWT authentication??
@pranjalmaurya3832
@pranjalmaurya3832 4 ай бұрын
After login same login page is rendering similar to that what was happening in your code(30:00), what can be done?
@unknown-vx6ei
@unknown-vx6ei 4 ай бұрын
Check if you have written method and action in your login ejs file 🤔
@myselfashutosh
@myselfashutosh 3 ай бұрын
is your error solved coz im aslo getting same
@theiitjourneytij3377
@theiitjourneytij3377 3 ай бұрын
@@myselfashutosh @unknown-vx6ei @pranjalmaurya3832 maybe in your code you are doing req.cookie.uid do one task do console.log(req) now you will se a last item cookie:"uid=something" but when you use cookieparser it will store your cookie in cookies so when you print the req object you will see two different keys in request object one is cookie and one is cookies:{uid:something} now in cookies you can access req.cookies.uid as in cookies uid is a key name of the inner object but in cookie it is uid="something" which means even if you use req.cookie?.uid then it will always return undefined as it doesnt have uid as key
@saiteja_13
@saiteja_13 Ай бұрын
same issue, anyone plz explain
@pallabdandapat1866
@pallabdandapat1866 Ай бұрын
27:30 --> cookie start
@NeerajSharma1
@NeerajSharma1 8 ай бұрын
Object Id create karte time apne ref: 'users' liya hai user ki jagah. Phr bhi ye work kar rha h. Why ?
@sanketmane4026
@sanketmane4026 5 ай бұрын
automatically mongodb me collections vaise hi create hota hai ... for example: const URL = mongoose.model("url", urlSchema); => show collections => urls for example: const User = mongoose.model("user", userSchema); ==> show collections => users model me tum koi aur name dalo aur mongosh me jake show collection karoge to tumhe dikhega
@souravkumar961
@souravkumar961 Ай бұрын
hmm, It seems like you merge two lecture in one video(authentication & cookie). for the first time, cookie implementation is much difficult then authentication.
@rishabhkedia9304
@rishabhkedia9304 12 күн бұрын
7:10 16:20 login 20:33 cookie 31:00
@bm9code
@bm9code 6 ай бұрын
zip file of knowledge
@sanchitasethi9885
@sanchitasethi9885 7 ай бұрын
My girlfriend 🤣🤣🤣🤣🤣 What an Easter egg hidden here haahahahaha
@namanjain1684
@namanjain1684 19 күн бұрын
why you don't explain anything like why you are using controller and what is that and other stuffs
@Chhotu668
@Chhotu668 12 сағат бұрын
He already explained in his previous videos in the playlist.
@cihadp
@cihadp 8 ай бұрын
What language do you speak?
@snehamaurya3659
@snehamaurya3659 5 ай бұрын
Hindi
@gtbaba123
@gtbaba123 2 ай бұрын
Bro use postman so that u don't have to waste time on creating FE as this video is totally focused on Node JS
@pranaavbv9359
@pranaavbv9359 2 ай бұрын
I mean, he's also giving us an idea about SSR 🤷🏿‍♂️
@buland_aavaj1130
@buland_aavaj1130 2 ай бұрын
bhai yrr ejs mat use krna kro na pls real world me kya use h iska
@gamerschoice779
@gamerschoice779 2 ай бұрын
Matlab?
@indrajitnaskar6851
@indrajitnaskar6851 4 ай бұрын
Sir, please first try once before video, instead it's so confusing
@joelosei765
@joelosei765 9 ай бұрын
If you make this video in English it's going to be great,
@kumaranupam8301
@kumaranupam8301 Ай бұрын
bkl
@sameerprajapati9467
@sameerprajapati9467 Ай бұрын
bhut he ghatiya padhaya hai
@Gulshankumar-yb3qb
@Gulshankumar-yb3qb 24 күн бұрын
Bhai kisse padhna chahiye batao
@user-be3pb2sf5s
@user-be3pb2sf5s 5 ай бұрын
if your video is not in english? so why are you writing the title in english??!! take my downvote
@gamerschoice779
@gamerschoice779 2 ай бұрын
Learn Hindi
@sourikray2291
@sourikray2291 2 ай бұрын
well...... there are lots of people like me over India who can understand hindi but can't read it properly so for me it's fine as it is
@prakharsinha4145
@prakharsinha4145 11 ай бұрын
req.user._id undefined .... anybody with the isssue ?
@myselfashutosh
@myselfashutosh 3 ай бұрын
yep bro same issue how did you solved
@036kaushik5
@036kaushik5 24 күн бұрын
user User.findOne({}) instead of User.find(), as the first method returns an object the latter returns an array of objects
@Ronakrewar
@Ronakrewar 14 күн бұрын
@@036kaushik5 req.user._id undefined .... anybody with the isssue ? how you resolved it
JWT Authentication in NodeJS
14:30
Piyush Garg
Рет қаралды 73 М.
Create a Custom URL Shortener using Node.JS and MongoDB
23:10
Piyush Garg
Рет қаралды 78 М.
OMG😳 #tiktok #shorts #potapova_blog
00:58
Potapova_blog
Рет қаралды 3,9 МЛН
Wait for the last one! 👀
00:28
Josh Horton
Рет қаралды 119 МЛН
Golang is OG?
5:16
Martin Baun
Рет қаралды 6 М.
Fastest way to become a Web Developer
9:47
Sahil & Sarra
Рет қаралды 555 М.
Server Side Rendering with EJS and Node.JS
25:24
Piyush Garg
Рет қаралды 54 М.
Creating Discord Bot in NodeJS
21:45
Piyush Garg
Рет қаралды 33 М.
Build Node.js User Authentication - Password Login
13:31
Web Dev Simplified
Рет қаралды 508 М.
Token vs Session Authentication | Authentication Explained!!!
15:19