Understanding Authentication in Node.js - Sessions and Cookies - Web Development Concepts Explained

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ก.ย. 2024
  • Understanding Authentication using Cookies and Sessions is a very important topic to understand in web development. I will be using Node.js and Express and MongoDB to build a very basic example of login and register.
    In this video I try my best to explain the basic workings of how this process of sessions and cookies work together to make it possible to authenticate users in you website.
    I hope you enjoy the video and if you did don't forget to like and subscribe and then I will see ya'll in the next one....🤓
    Express-Session Docs:
    www.npmjs.com/...
    Connect-MongoDB-Session Docs:
    www.npmjs.com/...
    If you want to know how To implement Authentication when building a RESTfull API go check out my video on this.
    My personal website
    =================
    www.thefullsta...

ความคิดเห็น • 290

  • @the_full_stack_junkie
    @the_full_stack_junkie  4 ปีที่แล้ว +40

    GitHub Repo for the project code in the video 🤓:
    github.com/LloydJanseVanRensburg/Authentication_Node_Sessions_Cookies
    Hope you liked this video. In the next authentication video I will be handling authentication from a API using JWT check it out in the web development concepts explained playlist!
    Have a great day peace out...

    • @engespress
      @engespress 3 ปีที่แล้ว +1

      Good tutorial. Thanks!

    • @elyasarkin0991
      @elyasarkin0991 2 ปีที่แล้ว +1

      Awesome and clean tutorial thank you

    • @mushfiqurniaz_
      @mushfiqurniaz_ 18 วันที่ผ่านมา

      I was about to comment if you don't put in source code you're gay but thanks

  • @muhammadjunaid3684
    @muhammadjunaid3684 3 ปีที่แล้ว +18

    What an amazing tutorial!
    I couldn't learn about sessions without this tutorial.
    Really love that 😍😍😍

  • @blackpeep984
    @blackpeep984 ปีที่แล้ว +1

    Holy shit bro this gotta be the best, easiest and most straightforward tutorial on sessions. Thank you very much!

  • @felakos1568
    @felakos1568 3 ปีที่แล้ว +3

    Very useful lesson and accessible presentation. Congratulations,
    you surpassed the whole Internet. Thank you sir.

  • @hand-somepaws9285
    @hand-somepaws9285 3 ปีที่แล้ว +2

    Perfectly explained. More information given. This is the best video I ever searched for.

  • @adeyemodavidsunday7140
    @adeyemodavidsunday7140 11 หลายเดือนก่อน

    Thank you so much for this wonderful piece I have been looking for a simplified authentication tutorial for so long but could not get one. I was able to follow your steps to implement AUTH using PostgreSQL database. Thanks a million times.

  • @balajeemishra
    @balajeemishra 3 ปีที่แล้ว +1

    Thank you sir. It was very useful. Today I understood what cookies actually do.

  • @VaibhavC-co1bi
    @VaibhavC-co1bi 6 หลายเดือนก่อน

    thank you man your lecture really helped me solving my issue

  • @bariswheel
    @bariswheel 2 ปีที่แล้ว

    I hope yo continue to make these videos, you have a gift!

  • @jamiroquaiordie
    @jamiroquaiordie ปีที่แล้ว

    thank you, finally understood how this works

  • @vipinr8473
    @vipinr8473 ปีที่แล้ว

    Thankyou for giving this wonderfull class thankyou so much

  • @magdyismail946
    @magdyismail946 ปีที่แล้ว +1

    Thank you
    This was very useful for me

  • @ravipayasi6875
    @ravipayasi6875 2 ปีที่แล้ว +1

    Amazing explanation, liked and subbed

  • @supriyasingh9818
    @supriyasingh9818 3 ปีที่แล้ว +1

    Its really good and straightforward video.

  • @stuff3704
    @stuff3704 ปีที่แล้ว +1

    thank you, great explanation

  • @hos7012
    @hos7012 2 ปีที่แล้ว +1

    best explanation

  • @drupalguy
    @drupalguy 2 ปีที่แล้ว +1

    Good tutorial. Thank you

  • @emilejuniorada6670
    @emilejuniorada6670 3 ปีที่แล้ว +22

    48hours. I've been struggling to understand those sessions things for 48 hours, making my ways through bunch of tutorials, and you just saved me. more follower

  • @nicogarcia7302
    @nicogarcia7302 3 ปีที่แล้ว +1

    Soo good, your tutorials are lit mate💯, subscribed !!

  • @ajwadmajed3551
    @ajwadmajed3551 2 ปีที่แล้ว +1

    A very Important question about this tutorial... how do i post the sign up (form) in Clientside Javascript with http post request? i don't see you using it in this tutorial ? do i need a fetch API on the client-side javascript?

  • @ayberkd9784
    @ayberkd9784 หลายเดือนก่อน

    Hi, how about expiration? Should we manually remove the session from the db? Or is there any way to do it automatically?

  • @roseahmed7741
    @roseahmed7741 3 ปีที่แล้ว

    Great video,Thank you so much,But i have one question what is the use of storing the session details in mongodb database?, without storing the session details in database the output of the program is same,hoping to get ans to my question.

  • @Getentertainedp
    @Getentertainedp 3 ปีที่แล้ว +1

    Subscribed!

  • @hakanaki
    @hakanaki 3 ปีที่แล้ว

    what happens if the cookie expires ??

    • @the_full_stack_junkie
      @the_full_stack_junkie  3 ปีที่แล้ว +1

      Hey man so i am going to answer both quesitons. First off sessions is data stored on the server that links to clients cookie. When making a http request in postman the cookie get set the same way it does in the browser and you can view the cookie data under the cookies tab in postman next to the response data.

    • @the_full_stack_junkie
      @the_full_stack_junkie  3 ปีที่แล้ว +1

      And a cookie gets delete by the browser when it expires.

    • @hakanaki
      @hakanaki 3 ปีที่แล้ว

      @@the_full_stack_junkie wow, this is amazing. Thank you very much 🤗

    • @hakanaki
      @hakanaki 3 ปีที่แล้ว

      @@the_full_stack_junkie I've been storing JWTs in local storage 🤦🏽‍♂️

    • @hakanaki
      @hakanaki 3 ปีที่แล้ว

      @@the_full_stack_junkie subscribing now 🏃🏾‍♂️

  • @shreyanshsahu4875
    @shreyanshsahu4875 2 ปีที่แล้ว

    In mongoose.connect(), useNewUrlParser, useUnifiedTopology, useFindAndModify, and useCreateIndex are no longer supported options. In new version i.e Mongoose 6 useNewUrlParser, useUnifiedTopology, and useCreateIndex are true, and useFindAndModify is false by default. So not necessary to write them.

  • @jesusenriqueperez5307
    @jesusenriqueperez5307 3 ปีที่แล้ว +42

    I've watched many videos about express-session and you are the first person that explains what is that cookie's purpose. Thank you

    • @the_full_stack_junkie
      @the_full_stack_junkie  3 ปีที่แล้ว +6

      Thanks so much very glad it helped champ

    • @sameerswankar
      @sameerswankar 8 หลายเดือนก่อน

      what happens when i open two tabs and login from different account on each of them, will the cookie gets overwritten ? How will that work

  • @Blazing_Hotmagma
    @Blazing_Hotmagma ปีที่แล้ว +4

    Think bros struggles with the Rs 💀

  • @unessss
    @unessss 3 ปีที่แล้ว +5

    I highly recommend this video to beginners... He explained EVERY line and word and code as simple as they could be...
    wish he covered the OAuth tho (like google login or other authenticating platforms )

  • @Abhisheky418
    @Abhisheky418 3 ปีที่แล้ว +10

    This was so clean , precise and to the point just loved it. thankyou for making this.

  • @florin1335
    @florin1335 3 ปีที่แล้ว +7

    Bro, I watched a few tutorials on this topic but yours was the best.

    • @the_full_stack_junkie
      @the_full_stack_junkie  3 ปีที่แล้ว +2

      I am very glad to hear this! Thanks so much for this comment

  • @rayensaidani600
    @rayensaidani600 2 ปีที่แล้ว +1

    "so tommy shelby is a web dev now"
    think you tho it was very helpful

  • @mohammedjoubba318
    @mohammedjoubba318 3 ปีที่แล้ว +2

    thank you , awesome explanation

  • @GaBlack-wo9vx
    @GaBlack-wo9vx 5 หลายเดือนก่อน +1

    This video is really helpful, thank you so much

  • @yehudahimelfarb5935
    @yehudahimelfarb5935 2 ปีที่แล้ว +2

    wow...excelent explication !!! 👏

  • @SanjuKumar-ye8xz
    @SanjuKumar-ye8xz 2 ปีที่แล้ว +1

    Very simply explanation. Thank dude☺️☺️☺️

  • @ajwadmajed3551
    @ajwadmajed3551 2 ปีที่แล้ว +1

    quick question.. do we need a fetch() API method to send the post request correctly? or is it correct to just use this tutorial ?

  • @mdjahidulislam9205
    @mdjahidulislam9205 2 ปีที่แล้ว +1

    everything is fine but in mobile browser cooke get destroyed automatically. if i close the browser and open it again.

    • @the_full_stack_junkie
      @the_full_stack_junkie  2 ปีที่แล้ว

      Yes this is so. Unless you set the expires value on the cookie then ut will only be removed once it has expired

  • @blank2782
    @blank2782 3 ปีที่แล้ว +3

    Amazing, clearly explained everything. Thankyou so much for this video.

  • @pankajjoshi8292
    @pankajjoshi8292 3 ปีที่แล้ว +4

    what is diff between EXPRESS and EXPRESS-SESSION?

    • @the_full_stack_junkie
      @the_full_stack_junkie  3 ปีที่แล้ว +1

      Express is web framework for node
      Express-session is a middleware package used for reading and crwating sessions

  • @Eddie4k
    @Eddie4k 2 ปีที่แล้ว +1

    Wow best video I have found tbh on this topic

  • @harrisonvijay8897
    @harrisonvijay8897 3 ปีที่แล้ว +3

    Thanks a lot for this video. It helped me, a beginner, understand cookies and sessions. Keep on posting!

  • @RMBK243
    @RMBK243 5 หลายเดือนก่อน +1

    amazing very helpful thanks

  • @__peanut__butter28
    @__peanut__butter28 3 ปีที่แล้ว +4

    this video simplified the cookie session, thanks a lot live more!

  • @liveecofriendly1116
    @liveecofriendly1116 2 ปีที่แล้ว

    After login successfully, if i change the url to /login and hit enter, it is taking me back to Login page, it shouldn't do that, because the login is successful, it should remain in dashboard page only.

  • @vladosononame6376
    @vladosononame6376 3 ปีที่แล้ว +2

    Why 3 people disliked it, they have no soul

  • @iganic7574
    @iganic7574 ปีที่แล้ว +2

    This is surely the easiest video about authontication 😍. Thanks bro your are amazing

    • @sameerswankar
      @sameerswankar 8 หลายเดือนก่อน

      what happens when i open two tabs and login from different account on each of them, will the cookie gets overwritten ? How will that work

  • @techyguyaditya
    @techyguyaditya 11 หลายเดือนก่อน

    Something's bugging me here. In the middleware isAuth, where does it check if isAuth true? Browser cookie or MongoDB session? If it's browser cookie then anyone can fake isAuth and access the dashboard.

  • @rules654
    @rules654 2 ปีที่แล้ว +1

    great work made, helped in my project.

  • @facundoloto1514
    @facundoloto1514 3 ปีที่แล้ว +2

    this video help me understand the seccions and the cookies of login and logout,after hours and days search ,thanks so much

  • @mohamadabdeen6906
    @mohamadabdeen6906 10 หลายเดือนก่อน +1

    great video ,thanks very much

  • @randomdudewithabeard7593
    @randomdudewithabeard7593 2 ปีที่แล้ว

    Hello,
    When I try to go to my dashboard page, I get this error :
    Cannot read properties of undefined (reading 'isAuth')
    What should I do ?

  • @captainalpha4853
    @captainalpha4853 ปีที่แล้ว

    Hello, I'm using express-session package. When i log in, i see that there is a cookie in the response.
    However, when i try to make a new request to the server, I don't see the cookie in the request header.
    PS: I'm using Nuxt3 for client side.

  • @vitorsanto1479
    @vitorsanto1479 2 หลายเดือนก่อน

    I have a question. I wanted to make a forum type site, I would like that after the user is authenticated show on a page as their data such as post, videos, message that he put on the site (through a form) how would I do this?

  • @walideker2253
    @walideker2253 7 หลายเดือนก่อน +2

    bruh tysm i hve been strugling over 2 weeks only ur video did it
    tysm

  • @dileepdilraj5254
    @dileepdilraj5254 3 ปีที่แล้ว

    Namaste,This is dileep dilraj.Actually I want to scrap a website which asking login to scrap details but the problem is to request the website "we have to now what is in the form" here I cant see details I have to fill in the form and it showing in the form ids: (number) ,Could you please help me to solve this problem.

  • @akinwekomitemitope4748
    @akinwekomitemitope4748 ปีที่แล้ว +1

    this is soooo simplified. its like some authentication and authorization courses🥰🥰🥰🥰🥰

    • @the_full_stack_junkie
      @the_full_stack_junkie  ปีที่แล้ว

      So glad you found it helpful 🤓

    • @adeyemodavidsunday7140
      @adeyemodavidsunday7140 11 หลายเดือนก่อน

      Thank you so much for this wonderful piece I have been looking for a simplified authentication tutorial for so long but could not get one. I was able to follow your steps to implement AUTH using PostgreSQL database. Thanks a million times.

  • @manishbhardwaj4587
    @manishbhardwaj4587 8 หลายเดือนก่อน +1

    love it, thank you Teacher!

  • @bossysmaxx3327
    @bossysmaxx3327 2 ปีที่แล้ว

    dude video is amazing but one question:::
    what is the purpose of saving the session in database?
    please give me answer
    below is bullshit, didn't wanted to write but I was forced.... sorry
    .
    .
    .
    .
    okay I did everything same as the video except that I didn't used connect-mongoose-session at all, it worked the same way, so what is the purpose of saving the session in database, whereas we all know that sessions are used till user close the browser and saving the session in db it's not useful....,
    we can use cookies to save userInfo for long period of time...., okay all I need to know is what is the purpose of saving session in database

  • @skmahmoodsameer2933
    @skmahmoodsameer2933 ปีที่แล้ว

    I have connected mongdb atlas, and connected successfully but there is no "session" database and "my_session" colleciton are being created automatically, as shown in video, why?

  • @dipeshmandanka
    @dipeshmandanka ปีที่แล้ว

    Can I use session across multiple modules like
    Student Login, register, Logout
    Teacher Login, Logout, regsiter
    Admin Login, Logout, register???

  • @charansrinivas3149
    @charansrinivas3149 3 ปีที่แล้ว +2

    Not working with reactjs. Cookies is not settinh up in browser

  • @哈里森-y9l
    @哈里森-y9l 3 ปีที่แล้ว +1

    Nice Share , thanks my bro , it's pretty worth for me !

  • @VijayTamada
    @VijayTamada ปีที่แล้ว +1

    Nice & to the point! Great!!

  • @TommyMN
    @TommyMN 11 หลายเดือนก่อน +1

    Thank you so much, I was searching the web for a good understanding of these subjects and you explained them very well my friend!

  • @franciscosalazar8116
    @franciscosalazar8116 ปีที่แล้ว +1

    Wow, this video is amazing!!!!!Thanks so much it wouldn't have been possible to understand this without your video!!! I could deploy my app finally thanks to you!!!

  • @ManeelxAkosAdor
    @ManeelxAkosAdor 3 ปีที่แล้ว +5

    outstanding tutorial man, thanks so much I learned a lot

  • @sameerswankar
    @sameerswankar 8 หลายเดือนก่อน

    what happens when i open two tabs and login from different account on each of them, will the cookie gets overwritten ? How will that work

  • @0xyz
    @0xyz 3 ปีที่แล้ว +1

    Great Video, Thanks for this

  • @PradeepKumar-fh2vs
    @PradeepKumar-fh2vs 2 ปีที่แล้ว +1

    I have watched many videos but did not get clear picture of how the session is working. your video has cleared my lots of doubts, Thanks for such a wonderful tutorial.

  • @xanderav
    @xanderav 2 ปีที่แล้ว +2

    As others have said I also watched many videos about this but this is THE BEST, it's just so clean, straightforward, it's amazing, thanks!

  • @AmanRaj-ho5qh
    @AmanRaj-ho5qh 2 ปีที่แล้ว +1

    The explanation is very clear

  • @byTwest
    @byTwest 2 ปีที่แล้ว

    If I am using react and routing on the frontend, how do I check if the user is authenticated to route them to protected pages?

  • @sidheart8905
    @sidheart8905 2 ปีที่แล้ว +1

    thank you very great and informative video... people are just tend to sue lot of addons or libraries , but from your video we can understand basic fundalmentals of authentication in nodejs using simple cookies and a database.

  • @vikram87in
    @vikram87in 2 ปีที่แล้ว +1

    great video... thanks 😍

  • @BrantK147
    @BrantK147 3 ปีที่แล้ว

    omg I think it's just me but that "r" is soooo distracting!!!! XD just curl your tongue man! not that hard XD

  • @katakuri8350
    @katakuri8350 3 หลายเดือนก่อน +1

    thank you so much

  • @harshad1704
    @harshad1704 3 ปีที่แล้ว +2

    one of the clear video on the express session very very thank you Junkie

  • @duggie3026
    @duggie3026 2 ปีที่แล้ว +1

    Thank you so much for the video. Your video helped me so much with the login and logout section.

  • @nagato6819
    @nagato6819 2 ปีที่แล้ว +1

    omg!! finally, I found a good video about authentication, thank you for this great explanation

  • @BaranivskyVadim
    @BaranivskyVadim 3 ปีที่แล้ว +1

    Yes I agree. Very good explanation. I watched many videos, only this made my work finished

  • @quanduong3390
    @quanduong3390 2 ปีที่แล้ว +1

    Thank you so much for making this. You explained it well. Thank you

  • @claudiovitordantas2348
    @claudiovitordantas2348 3 ปีที่แล้ว +2

    man, this is the best video on how to do a simple authentication on nodejs! congrats!!

  • @ashfaquemamdu4582
    @ashfaquemamdu4582 2 ปีที่แล้ว +1

    Thanks man it was helpful

  • @samjacker
    @samjacker 3 หลายเดือนก่อน +1

    thank you so much

  • @editingtuto1.011
    @editingtuto1.011 ปีที่แล้ว

    Whenever I clicked on logout button. Session is not getting deleted from Database

  • @serenliceackeric9732
    @serenliceackeric9732 ปีที่แล้ว +1

    Best explanation !! thank u so much

  • @henrynwosu6277
    @henrynwosu6277 ปีที่แล้ว

    Thank you for the Tutorial.
    But I have a question.
    Just After you installed the session middleware, you did this;
    req.session.isAuth = true and it affected the client by giving you a cookie ID on the browser without you needing to send a response.
    How is this possible. I thought the only way for the server to communicate with the client in a http transaction is through the response object.
    I'm really confused. I have been searching Google to see perhaps there is some Abstraction in the session Middleware that I am not aware of.
    Thank you.

    • @techyguyaditya
      @techyguyaditya 11 หลายเดือนก่อน

      Yeah I am having the same doubt. If isAuth is set true by client, then dashboard is viewed without verification of if session is valid or not.

  • @codefork94
    @codefork94 2 ปีที่แล้ว +1

    Dude!!!! I finally get it!!!!

  • @theclub372
    @theclub372 3 ปีที่แล้ว +1

    Thanks for the video man. How do I go about authorization? Do I just store a property in the session?

  • @souravvashisht7153
    @souravvashisht7153 2 ปีที่แล้ว +1

    Thank you very Much.

  • @ВладимирМогилин-д9ш
    @ВладимирМогилин-д9ш 2 ปีที่แล้ว

    Finally, I figured out user authentication thanks to your video, thanks a lot.
    One little question: Is "isAuth" special method of express-session module? Ican't find it in documentation.

    • @agustinblanco4168
      @agustinblanco4168 2 ปีที่แล้ว +1

      No, is just an attribute he creates to store the boolean. You can name it however you want.

  • @carlsagan9808
    @carlsagan9808 ปีที่แล้ว +1

    Great sessions tutorial!

  • @fatimaarshad8100
    @fatimaarshad8100 ปีที่แล้ว +1

    I'm really thankful that you solve my problem I was stuck like from 2 days and I don't get it why my session and passport auth not working. Your method of teaching is more calm and understandable. I'm really thankful to you

  • @indianafootballer3257
    @indianafootballer3257 3 ปีที่แล้ว +2

    thank you... so understandable.. best taught ❤️❤️

  • @UskiGaming
    @UskiGaming 8 หลายเดือนก่อน

    I'm a little late to the party, but I have a question: if I somehow obtain the ID from the session cookie of another user and manually insert a cookie into my browser, can I log in to that user's session? If so, is there any way to prevent this?

    • @sameerswankar
      @sameerswankar 8 หลายเดือนก่อน

      what happens when i open two tabs and login from different account on each of them, will the cookie gets overwritten ? How will that work

  • @benzemamumba
    @benzemamumba ปีที่แล้ว +1

    You've got an Afrikaans accent.

  • @giddyvibes-0423
    @giddyvibes-0423 11 หลายเดือนก่อน +1

    Am the type that really found it hard to understand but this video is solid Gold

  • @xosound5938
    @xosound5938 3 ปีที่แล้ว +2

    Nice tutorial man!!! You really explained everything so well. Thanks 😊

    • @the_full_stack_junkie
      @the_full_stack_junkie  3 ปีที่แล้ว

      Thanks for comment champ hope to keep making content that helps

  • @ayomichaels1204
    @ayomichaels1204 ปีที่แล้ว +1

    This is super helpful

  • @editingtuto1.011
    @editingtuto1.011 ปีที่แล้ว

    What we are taking req session.isAuth = true. And what if we not initialise it?